2012-04-16 75 views
-3

好的,所以我100%全新的从Facebook上分享C#的东西。如何在Facebook上分享位图作为C#中的照片?

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

请不要回答(谷歌,我知道二硝基甲苯,为什么?不可能,Facebook的SDK)...

+2

我会回答“你到目前为止尝试了什么?” – RQDQ 2012-04-16 18:22:09

+3

您是否尝试过Google,Facebook文档等? – 2012-04-16 19:23:31

回答

1

你的问题是有点含糊。当你说“用C#”时,你的意思是在网页,窗口或服务环境中?因为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 
} 

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