Reputation: 1425
I have used JSDK to authenticate user for my facebook app. I am getting the access token but it gets expired within 1/2 hours. So how can I get long term Access Token?
The code I have used is:
var fb = new FacebookClient();
Dictionary<string,Object> sParams=new Dictionary<string,Object>();
sParams.Add("client_id",My_App_ID);
sParams.Add("client_secret",My_App_Secret);
sParams.Add("grant_type","fb_exchange_token");
sParams.Add("fb_exchange_token",Short_lived_accessToken);
dynamic result = fb.Get("oauth/access_token",sParams);
fb.AccessToken = result.access_token;
but it gives me error Invalid JSON String at line dynamic result = fb.Get("oauth/access_token",sParams);
What wrong am I doing here?
Upvotes: 2
Views: 1448
Reputation: 1484
Use this code:
var client = new FacebookClient(Short_lived_accessToken);
dynamic result = client.Post("oauth/access_token", new
{
client_id = My_App_ID,
client_secret = My_App_Secret,
grant_type = "fb_exchange_token",
fb_exchange_token = Short_lived_accessToken
});
Response.Write("Long live access token: [" + result.access_token + "]");
Hope it helps.
Upvotes: 4
Reputation: 96250
The return you will get from the endpoint simply is not JSON, but just plain text in the form
access_token=new_long-lived_access_token&expires=5130106
So you will have to tell your application somehow(?), that the result is not JSON; or you might have to use a different method altogether to make the request, if FacebookClient::Get always expects the answer to be JSON.
Upvotes: 1