1

I am trying to access my Facebook account with an App access code (because I want indefinate access - I do not want an access code which can expire)

I have tried the following code using AppId and AppSecret (which are valid) :

string accesstoken = m_AppId & "|" & m_AppSecret;
Facebook.FacebookClient fb = new Facebook.FacebookClient(accesstoken); 
Facebook.JsonObject fbMe = (Facebook.JsonObject)fb.Get("me"); 

and the last line throws an exception stating

OAuth Exception #2500 An active access token must be used to query information about the current user."

What am I doing wrong here ?

Martha
  • 81
  • 1
  • 1
  • 8

1 Answers1

3

If you're using an App Access Token, the path me cannot be determined by the Graph API, because the App Access Token is not connected to a specific User.

Solution is either specify a (app-scoped if using Graph API v2.0) user_id instead of me, or use a User Access Token.

Tobi
  • 31,405
  • 8
  • 58
  • 90
  • Thank you for your response. 1) My facebook logon/account has three fields forename,surname,email address. How do I use these to obtain a user_id? 2) Do User Access Tokens expire, if they do, I don't think they are suitable. I need to have indefinite access. – Martha May 28 '14 at 15:20
  • You should definitely use User Access Tokens, because otherwise you'll not be able to retrieve more than the `basic_profile`. The stuff you tried will not work. Regarding expiration, you're not the first developer which has to deal with that. Read the docs. – Tobi May 28 '14 at 15:24
  • I don't think you understood. If you want to access for example the Email address, you have no choice but to use a User Access Token. – Tobi May 29 '14 at 09:31
  • I want to access posts on my facebook pages from server code. I dont mind what type of access token I use as long as it will last indefinitely (subject to password not being changed of course). Is this possible? Thanks. – Martha May 29 '14 at 12:28
  • See my answer at http://stackoverflow.com/questions/23907802/post-to-a-facebook-page-without-manage-pages-permission-using-php/23908207#23908207 and be sure to add the read_stream permission as well – Tobi May 29 '14 at 18:05
  • Thank you for posting this I appreciate it. It does not help unfortunately. The initial access token was 1 hour and the extended one was 2 months. As I said - I need an indefinite access time access token. Is this possible ? – Martha Jun 04 '14 at 11:39
  • Have you read my answer about Page Access Tokens? These are indefinite. Have you tried this? – Tobi Jun 04 '14 at 12:23
  • Yes thanks. I did try it. I followed it through, extended the access token and then pasted it into the graph API debug page and that said the token expires in "about 2 months". – Martha Jun 04 '14 at 14:59
  • I tried this with one of my v1.0 apps, and this works. tried it with one of my v2.0, and indeed there's a 2 month validity. Do you happen to have a v1.0 app? – Tobi Jun 04 '14 at 15:08
  • no it is a v2.0 App. I understood that all new Apps have to be V2.0 ? – Martha Jun 04 '14 at 15:16
  • All new apps since April 30th 2014 are V2.0. Afaik the validity change is not documented. – Tobi Jun 04 '14 at 15:28