Question

I try to get all user photo by using FQL (Facebook C# SDK, ASP .NET MVC, VB, iFrame Canvas application). My code is following:

Dim app As New FacebookApp()
Dim result As New List(Of FB_Picture)
Dim photoList As Object = app.Fql("SELECT src_small,src_big,src,caption FROM photo WHERE aid IN ( SELECT aid FROM album WHERE owner=" + FacebookId.ToString() + " ) ORDER BY created DESC LIMIT " + FromN.ToString() + "," + ToN.ToString())

For i As Integer = 0 To photoList.Count
result.Add(New FB_Picture() With {.Caption = photoList(i).caption, .Src = photoList(i).src, .Src_big = photoList(i).src_big, .Src_small = photoList(i).src_small}) 
Next
Return result

FB_Picture is my class to store user pictures.

My app has user_photos permissions.

But I have a error - Invalid OAuth 2.0 Access Token

FacebookOAuthException: Invalid OAuth 2.0 Access Token]
Facebook.FacebookApp.MakeRequest(HttpMethod httpMethod, Uri requestUrl, Byte[] postData, String contentType) +393
Facebook.<>c__DisplayClassf.<OAuthRequest>b__e() +20
Facebook.FacebookApp.WithMirrorRetry(Func`1 body) +225
Facebook.FacebookApp.OAuthRequest(Uri uri, IDictionary`2 parameters, HttpMethod httpMethod) +338
Facebook.FacebookApp.RestServer(IDictionary`2 parameters, HttpMethod httpMethod) +481
Facebook.FacebookAppBase.Api(String path, IDictionary`2 parameters, HttpMethod httpMethod) +236
Facebook.FacebookAppBase.Api(IDictionary`2 parameters) +132
Facebook.FacebookAppExtensions.Fql(FacebookAppBase app, String query) +310

Could you help me? What can I fix? Can I use FQL by using Facebook C# SDK?

Was it helpful?

Solution

You need to have an active session to make an FQL query. Check out the samples in the newest release of the Facebook C# SDK for help on how to get an access token. Once you have an access token, just change your code to the following:

Dim app As New FacebookApp("your_access_token_here")

OTHER TIPS

There is one thing that the developers of the Facebook SDK don't make clear to new users of the SDK or indeed new folks approaching Facebook development.

The Facebook SDK is obviously a wrapper, but it's a wrapper on top of cookies. What this means at the end of the day is that Facebook maintain the session state for your application. You don't maintain it, they do. So any time a user of your application clicks a link within your application and you want to track that user (or more precisely that session) you need to ensure your link points to a url such as:

http://apps.facebook.com/Your_Application_Name_Here

and not:

http://www.Your_Application_Name_Here.com

if you don't then Facebook can't track the session and you have effectively left their domain. You will notice this if you do the mistake that I did when I was writing link's out in my views using Url.Action:

<a href="<%= Url.Action("CreateOrder", "Home") %>">Create an Order</a>

I kept getting a similar error to yours. That's why Totten and the other guy that wrote the SDK gave you helper methods such as:

<%= Url.CanvasAction("CreateOrder", "Home") %>

HTH

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top