Sto sviluppando un'applicazione per Android. Con l'imminente deprecazione dell'autorizzazione offline_access di Facebook, sto cercando di utilizzare l'API Graph per estendere il token di Facebook.Qual è il codice per ottenere un token Facebook aggiornato in un'app Android?
https://graph.facebook.com/oauth/access_token?
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN
Qualcuno può fornire il codice dettagliato che illustra come implementare il codice sopra in un app Android e ottenere il rinfrescato Facebook gettone?
Grazie per il vostro tempo.
aggiornare due:
Progress (credo)!
Utilizzando l'URL completo con il metodo di richiesta facebook comporta l'URL di base viene aggiunto al all'inizio del URL Così, invece di
String refreshUrl = "https://graph.facebook.com/oauth/access_token?client_id=12345678910&client_secret=abcdefghijklmnopqrstuvwxyz&grant_type=fb_exchange_token&fb_exchange_token="+currentAccessToken;
dovrebbe usare
String refreshUrl = "oauth/access_token?client_id=12345678910&client_secret=abcdefghijklmnopqrstuvwxyz&grant_type=fb_exchange_token&fb_exchange_token="+currentAccessToken;
Comunque sono ora ricevendo la risposta {"errore": {"messaggio": "Errore di convalida dell'applicazione. ID applicazione non valido.", "tipo": "OAuthException", "codice": 190}}
Aggiornamento uno:
Ecco cosa ho provato. Il codice viene completato, ovvero OnComplete sul lister viene chiamato, MA la risposta non contiene un nuovo token di accesso o un valore di scadenza.
void refreshWithGraph() {
AsyncFacebookRunner extendingAsyncRunner = new AsyncFacebookRunner(facebook);
Bundle parameters = new Bundle();
//the variable currentAccessToken is obtained after authorisation is complete using currentAccessToken = facebook.getAccessToken();
String refreshUrl = "https://graph.facebook.com/oauth/access_token?client_id=12345678910&client_secret=abcdefghijklmnopqrstuvwxyz&grant_type=fb_exchange_token&fb_exchange_token="+currentAccessToken;
extendingAsyncRunner.request(refreshUrl, parameters, new RefreshListener(), null);
}
Ecco la mia versione di RefreshListener ...
//REFRESH LISTENER
public class RefreshListener extends BaseRequestListener {
public void onComplete(final String response, Object state) {
try {
final JSONObject json = Util.parseJson(response);
runOnUiThread(new Runnable() {
@Override
public void run() {
tvRefreshResponse.setText("IN REFRESH LISTENER ONCOMPLETE\nResponse is " + response);
tvRefreshToken.setText("IN REFRESH LISTENER ONCOMPLETE\nToken is " + facebook.getAccessToken());
tvRefreshExpiry.setText("IN REFRESH LISTENER ONCOMPLETE\nFacebook expiry is " + millisecToDate(facebook.getAccessExpires()));
}
}); //end runOnUiThread
} catch (JSONException e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
tvRefreshResponse.setText("IN REFRESH LISTENER ONCOMPLETE CAUGHT JSON EXCEPTION \nResponse is " + response);
}
}); //end runOnUiThread
} catch (FacebookError fe) {
runOnUiThread(new Runnable() {
@Override
public void run() {
tvRefreshResponse.setText("IN REFRESH LISTENER ONCOMPLETE CAUGHT FACEBOOK ERROR \nResponse is " + response);
}
}); //end runOnUiThread
} //end catch Facebook error
} //end onComplete
@Override
public void onIOException(IOException e, Object state) {
tvRefreshResponse.setText("IN REFRESH LISTENER IOEXCEPTION \nException is "+ e.getLocalizedMessage());
}
@Override
public void onFileNotFoundException(FileNotFoundException e, Object state) {
tvRefreshResponse.setText("IN REFRESH LISTENER FILE NOT FOUND EXCEPTION \nException is "+ e.getLocalizedMessage());
}
@Override
public void onMalformedURLException(MalformedURLException e, Object state) {
tvRefreshResponse.setText("IN REFRESH MALFORMED URL \nException is "+ e.getLocalizedMessage());
}
@Override
public void onFacebookError(FacebookError e, Object state) {
tvRefreshResponse.setText("IN REFRESH ONFACEBOOK ERROR \nException is "+ e.getLocalizedMessage());
}
} //end RefreshListener
Il codice completa, cioè OnComplete sul listerner si chiama, ma la risposta non contiene un nuovo accesso valore simbolico o di scadenza. La risposta è ...
{"id":"https:\/\/graph.facebook.com\/oauth\/access_token","shares":78,"comments":1}
Quando ho messo lo stesso URL (con un valore simbolico corrente alfanumerico) in un browser web la risposta include un token di accesso.
Informazioni relative al
il permesso offline_access di Facebook sarà deprecato il 1 maggio 2012
Si prega di non suggerire utilizzando la funzione extendAccessTokenIfNeeded in onResume(), invece.I am also having trouble con quello ed è la ragione per cui sto cercando in token :-) rinfrescante Graph API
correlati Stack Overflow domande
Is it possible to extend Facebook tokens with extendAccessTokenIfNeeded in an Android app? (la mia domanda)
How would offline_access work after deprecation after May 1st?
Facebook access token can not be extended
Protecting app secret for extendAccessToken usage (Java/Android)
Rilevante Facebook collega
Facebook offline_access permission deprecation
Con tutti i link sopra, perché avete bisogno di informazioni più dettagliate? Sembra che tu abbia abbastanza documentazione per implementare questo .. – Shreeni
Penseresti che potrei risolverlo, ma no. :-(Tutta la facile domanda su Stack Overflow ha una risposta completa molto rapidamente, quindi immagino che non sia così facile come sembra ... – Mel