如何在 C# 中将位图共享为照片在 facebook 上

本文关键字:照片 facebook 共享 位图 | 更新日期: 2023-09-27 18:31:13

好的,所以我对在Facebook上分享C#的东西是100%的新手。

我需要如何在我的Facebook上分享图像作为照片的示例代码?

请不要回答(谷歌它,我不知道,为什么?,不可能,Facebook SDK)...

如何在 C# 中将位图共享为照片在 facebook 上

你的问题有点模糊。 当您说"在 C# 中"时,您是指在 Web、窗口或服务环境中? 因为Facebook这样做的方式是在此过程中必须进行一些身份验证,这是通过重定向到Facebook让用户登录,然后发送照片进行共享来实现的。这是一个相当的过程,而不仅仅是一个神奇的单行代码。

在任何情况下,您都必须执行以下操作,并且必须确定将其放置在环境中的位置:

  1. 创建与您的应用程序相对应的Facebook应用程序;然后,Facebook会给你一个应用程序代码和一个应用程序密码。
  2. 使用应用代码,重定向到 Facebook,对想要在其 Facebook 上共享照片的用户进行身份验证。
  3. 从Facebook接收代码。
  4. 通过服务调用与 Facebook 通信来授权您的应用,以允许使用应用代码、应用密码和我们从步骤 2 中获得的代码共享照片。
  5. 从Facebook接收一个令牌,从现在开始将用于上传照片。
  6. 现在,您可以使用该令牌开始通过另一个服务调用将照片上传到Facebook。

代码如下:

// Step 2: you have to research what TheScope will be from Facebook API that gives you access to photos
Response.Redirect(string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&scope={1}&redirect_uri={2}"), MyAppCode, TheScope, MyRedirectingURL);
// Step 3: this is on the `Page_Load` of MyRedirectingURL.
// AnotherRedirectingURL will be your final destination on your app
using (var wc = new WebClient())
{
    string token = wc.DownloadString(string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&code={2}&redirect_uri={3}", MyAppCode, MyAppSecretCode, TheCode, AnotherRedirectingURL));   
}
// Step 4:  Use the token to start stream up or down
using (var wc = new WebClient())
{    
    Uri uploadUri = new Uri(string.Format("https://graph.facebook.com/{0}?{1}", PhotoUploadCommand, token));     
    // Find out what the PhotoUploadCommand is supposed to be from the Facebook API
    // use wc and uploadUri to upload the photo
}

底线,你必须对此进行研究... 事情没那么简单。 这是一个可悲的事实,我必须经历才能做你正在做的事情。