Reputation: 6941
I am trying to extend my facebook access token, and following is what I did. However, i wasn't able to get the token extended, and when I check the facebook accesstoken debugger it still shows that the token is expiring in an hour.
any ideas?
private string appId = "my app id";
private string appSecret = "my app secret";
private string returnUrl = "http://localhost:1868/callback";
private string _scope = "user_about_me,publish_stream,user_videos,user_photos";
[Test]
public void GetFacebookLoginUrl()
{
var fb = new FacebookClient();
dynamic result = fb.GetLoginUrl(
new
{
client_id = appId,
client_secret = appSecret,
redirect_uri = returnUrl,
response_type = "code",
scope = _scope
}
);
}
[Test]
public void exchangeCodeForAccessToken()
{
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new
{
client_id = appId,
client_secret = appSecret,
redirect_uri = returnUrl,
code = "got the code after user accepts the request"
});
}
[Test]
public void ExtendExpiryTimeOfAccessToken()
{
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new
{
client_id = appId,
client_secret = appSecret,
grant_type = "fb_exchange_token",
fb_exchange_token = "token from preview method"
});
}
Solution
after de-authorize the app from the users' accounts everything start making sense. One thing to note tho, the code above actually gets a "long lived" access token back which is valid for 60 days and it can not be extended.
if a Facebook client-side authentication is used, then one can extend it using the "ExtendExpiryTimeOfAccessToken" sample.
Upvotes: 0
Views: 541
Reputation: 1567
If you initially started developing the application and signing in months ago before the offline access depreciation it is possible your affected by this bug.
https://developers.facebook.com/bugs/341793929223330
If you are affected you need to de-authorise the application and then try again, this doesn't affect new users.
Upvotes: 2