Cómo obtener la fecha de caducidad del token de acceso en Facebook SDK para Unity

I am using parse sdk for backend management for my game. For user signup/login parse api ask for parameter tokenExpiration. I have no idea how to get it from facebook unity sdk. https://www.parse.com/docs/unity_guide#fbusers-signup

Task<ParseUser> logInTask = ParseFacebookUtils.LogInAsync(accessToken, userId, tokenExpiration);

preguntado el 09 de septiembre de 13 a las 23:09

2 Respuestas

Got this problem solved by myself using debug_token. Here is the right code on how to do it.

FB.API("/debug_token?input_token="+FB.AccessToken+"&access_token="+FB.AccessToken,Facebook.HttpMethod.GET, AccessTokenCallback);
function AccessTokenCallback(response:String){
Debug.Log(response);
var access = JSON.Parse(response);
Debug.Log("Token Expiration is: "+access["data"]["expires_at"].Value);
}

If you will print the response it will give you a JSON with all information about the access token and you can take whatever info you need about an access token.

Respondido el 19 de Septiembre de 13 a las 20:09

Open FacebookAccessTokenEditor.cs and replace original line 81:

formData["batch"] = "[{\"method\":\"GET\", \"relative_url\":\"me?fields=id\"},{\"method\":\"GET\", \"relative_url\":\"app?fields=id\"}]";

by these two:

string getExpiresAt = ",{\"method\":\"GET\", \"relative_url\":\"debug_token?input_token="+accessToken+"\"}";
formData["batch"] = "[{\"method\":\"GET\", \"relative_url\":\"me?fields=id\"},{\"method\":\"GET\", \"relative_url\":\"app?fields=id\"}"+getExpiresAt+"]";

Then open FacebookEditor.cs and in method MockLoginCallback, just before line 220:

isLoggedIn = true;

insert the following lines:

var tokenData = (Dictionary<string, object>)MiniJSON.Json.Deserialize(responses[2]);
var expiresAt = (long)((Dictionary<string, object>)tokenData["data"])["expires_at"];
accessTokenExpiresAt = FromTimestamp((int)expiresAt);

also, add the missing function FromTimestamp which you can copy from AndroidFacebook.cs or IOSFacebook.cs or jus copy from here:

private DateTime FromTimestamp(int timestamp)
{
    return new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(timestamp);
}

Finally, you can call the parse method like you do on IOS or Android or Web:

Task<ParseUser> logInTask = ParseFacebookUtils.LogInAsync(FB.UserId, FB.AccessToken, FB.AccessTokenExpiresAt);

Note: As I have worked on the code, I am not sure of the original line numbers, but I think they are correct. Also, this does not reflect the best coding practices, but since it is used only in a debug context, they're good enough for me.

Respondido 18 Jul 14, 23:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.