使用C#从Facebook获取照片和相册 [英] Obtaining Photos and Albums from Facebook using C#

查看:92
本文介绍了使用C#从Facebook获取照片和相册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Facebook C#SDK从Facebook解析并获取我的相册(我的个人帐户而非我的应用程序).我的目标是在我的帐户中抓取10-12张最新照片.但是,我知道我必须先抓专辑.

I'm trying to parse through and obtain my (my personal account not my app) albums from Facebook using the Facebook C# SDK. My goal is to grab the 10-12 most recent photos on my account. However, I understand I have to grab the albums first.

因此,我尝试了很多事情,最后得到了以下返回400错误请求的网址:

So, I've tried numerous things and ended up with the following url which returns a 400 Bad Request:

https://graph.facebook.com/{my_user_id}/albums?access_token={my_access_token}

令牌通过调用获得:

https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&grant_type={2}&scope={3}

我为什么要得到400的任何想法?

Any ideas why I'd be getting the 400?

推荐答案

在使用grant_type = client_credentials时,您需要的是应用访问令牌.这将允许您对应用程序执行各种管理操作.请参见 http://developers.facebook.com/docs/authentication/中的应用程序登录.

When using grant_type = client_credentials you're requesting the an app access token. This will allow you to do various administrative actions for your application. See App Login in http://developers.facebook.com/docs/authentication/.

但是,在使用Graph Api的用户部分时,您需要使用oAuth对话框执行用户登录.有多种方法可以做到这一点,例如使用 JavaScript SDK 即可,使用.

However, when using the user-parts of the Graph Api you need to perform a User Login using the oAuth Dialog. There are different ways of doing this such as with the Javascript SDK which should be straightforward to use.

我没有找到在独立的Web应用程序中使用 Facebook C#SDK 的好方法Javascript SDK(使用CanvasAuthorize属性在画布应用程序中很容易).

I've not found a nice way of doing this in a standalone web app using Facebook C# SDK without the Javascript SDK (it's easy in a canvas app using the CanvasAuthorize attribute).

这是WinForms应用程序中的操作方法示例 http://blog.prabir.me/post/Facebook-CSharp-SDK-Writing-your-first-Facebook-Application.aspx .如果可以使用WebBrowser控件,则它可能在Asp.Net应用程序中有效.我已经尝试过使用WebClient,但是没有任何运气.

Here's an example of how to do it i a WinForms app http://blog.prabir.me/post/Facebook-CSharp-SDK-Writing-your-first-Facebook-Application.aspx. It might work in a Asp.Net app if you could use the WebBrowser control. I've tried with WebClient but didn't have any luck.

更新

通过在此处查看示例 http: //facebooksdk.codeplex.com/SourceControl/changeset/view/534da45e108f#Samples%2fCSMvcWebsite%2fControllers%2fHomeController.cs ,看来您应该能够在独立站点中使用FacebookAuthorize属性.

By looking at the sample here http://facebooksdk.codeplex.com/SourceControl/changeset/view/534da45e108f#Samples%2fCSMvcWebsite%2fControllers%2fHomeController.cs it looks like you should be able to use the FacebookAuthorize attribute in a standalone site.

这篇关于使用C#从Facebook获取照片和相册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆