prabirshrestha / FacebookSharp

Facebook Graph API for .Net
Other
30 stars 15 forks source link

Offline Access not working #15

Open jacobh0 opened 13 years ago

jacobh0 commented 13 years ago

I have offline_access as a permission to request, so I save the AccessToken from FB.AccessToken in my database after verifying the session is valid, but when I use this token from the DB in a call to newFB = new Facebook(accesstoken) and then proceed to do a call such as FacebookExtensions.PostToWall(newFB, "Message to my own wall!") I receive an invalid oauth token error.

jacobh0 commented 13 years ago

The token looks like this:

102072096507053|91ef4e3a32fbbc6bed1acffc-594308005|uH0gVxpWJFLFV0FC_pdLYGSDMV4

prabirshrestha commented 13 years ago

are you sure you have "publish_stream" access also?

you can see more of these extended permissions from http://developers.facebook.com/docs/authentication/permissions

jacobh0 commented 13 years ago

Yes I have publish_stream requested as well...

prabirshrestha commented 13 years ago

i just tried with the winforms sample and it works.

in btnLogin_Click i changed to the follwing code:

FacebookSettings fbSettings = new FacebookSettings { ApplicationKey = txtApiKey.Text, DefaultApplicationPermissions = new[] { "publish_stream", "offline_access" } };

and in btnGetMyInfo_Click Facebook fb = new Facebook(txtAccessToken.Text); var id = fb.PostToWall("message to my own wall", null);

it works. do you have the latest code? (actually it should be working even if you don't have the latest code. anyways could u download the latest code and try again.)

jacobh0 commented 13 years ago

I have the latest code, it worked when I called it with the expiration parameter set to 0:

fb.PostToWall("Message to my own wall!", 0)

It would not work without the 2nd parameter, I am using an iframe application.

prabirshrestha commented 13 years ago

there are some overloads to PostToWall. the first parameter is the message: "message to my own wall" but the second parameter is not expiration parameter, it is additional parameters which is a dictionary object. usually you would set it to null, but in case u r posting link,picture or something else then you might want to modify this custom parameter.

and some overloads contains the 3rd parameter called profileId, this is where you want to post to. lets say u are user A and u want to post to user B's wall. then you would do fb.PostToWall("message to B",null, user_id_of_b);

if you want to post to your own wall. fb.PostToWall("message to myself",null,user_id_of_myself_that_is_A); or fb.PostToWall("message to myself",null,"me"); or shorthand fb.PostToWall("message to myself",null); // by default posts to my wall

im wondering how you could even compile fb.PostToWall("Message to my own wall!", 0) coz 0 is not a IDictionary<string,string> so it would have a compile error. unless you mean null. and PostToWall has no overloads accepting expiration parameter.

jacobh0 commented 13 years ago

Sorry I meant fb = new Facebook(AccessToken, 0); not 0 for PostToWall, post to wall worked fine when I set the expiration when defining the new Facebook object.

prabirshrestha commented 13 years ago

that constructor was actually written to make it compatible with the original Android SDK written in Java which i ported from. even other methods such as SetAccessExpiresIn

for now could u use the another overloaded constructor that passes only access token. i will have a look at the one that passes the expires token.

thanks.

prabirshrestha commented 13 years ago

in Facebook.cs line number 123, there seems to be some problem when comparing date and time. that is making it fail when u specify the expires in. i will have a loot at it.

if (DateTime.Compare(FacebookUtils.Date.FromUnixTimestamp(AccessExpires), DateTime.UtcNow) > 0)

jacobh0 commented 13 years ago

It fails when you do NOT specify the expiration.

prabirshrestha commented 13 years ago

for now i have commented out the checking of IsSessionValid on PutObject extension method. (it is a temporary fix.) could you try to download the latest source code and try it again.