2012-12-14 9 views
11

Ich versuche Facebook-Integration in meine Android-App zu implementieren und es geht los und meldet sich in Facebook gut, aber wenn es versucht, das Access Token zurück zur App zu geben, gibt es einfach zurück:Facebook-Integration auf Android fbconnect defekten Link

Die Webseite unter fbconnect: // Erfolg # access_token = [ACCESS TOKEN] ist möglicherweise vorübergehend oder dauerhaft an eine neue Web-Adresse bewegt haben.

Offensichtlich, wo [ACCESS TOKEN] eine lange Folge von Zeichen ist.

Ich habe die App ID korrekt und den Schlüssel Hash Facebook hinzugefügt. Aber welchen Prozess könnte ich verpasst haben?

Code:

public class FacebookActivity extends Activity { 

private static final String APP_ID = "[MY APP ID]"; 
private static final String[] PERMISSIONS = new String[] {"publish_stream"}; 

private static final String TOKEN = "access_token"; 
    private static final String EXPIRES = "expires_in"; 
    private static final String KEY = "facebook-credentials"; 

private Facebook facebook; 
private String messageToPost; 

public boolean saveCredentials(Facebook facebook) { 
     Editor editor = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE).edit(); 
     editor.putString(TOKEN, facebook.getAccessToken()); 
     editor.putLong(EXPIRES, facebook.getAccessExpires()); 
     return editor.commit(); 
    } 

    public boolean restoreCredentials(Facebook facebook) { 
     SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE); 
     facebook.setAccessToken(sharedPreferences.getString(TOKEN, null)); 
     facebook.setAccessExpires(sharedPreferences.getLong(EXPIRES, 0)); 
     return facebook.isSessionValid(); 
    } 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    facebook = new Facebook(); 
    restoreCredentials(facebook); 

    requestWindowFeature(Window.FEATURE_NO_TITLE); 

    setContentView(R.layout.activity_facebook); 

    String facebookMessage = getIntent().getStringExtra("facebookMessage"); 
    if (facebookMessage == null){ 
     facebookMessage = "Test wall post"; 
    } 
    messageToPost = facebookMessage; 

      if (! facebook.isSessionValid()) { 
     loginAndPostToWall(); 
    } 
    else { 
     postToWall(messageToPost); 
    } 
} 

public void loginAndPostToWall(){ 
    facebook.authorize(this, APP_ID, PERMISSIONS, new LoginDialogListener()); 
} 

public void postToWall(String message){ 
    Bundle parameters = new Bundle(); 
      parameters.putString("message", message); 
      parameters.putString("description", "topic share"); 
      try { 
       facebook.request("me"); 
     String response = facebook.request("me/feed", parameters, "POST"); 
     Log.d("Tests", "got response: " + response); 
     if (response == null || response.equals("") || 
       response.equals("false")) { 
      showToast("Blank response."); 
     } 
     else { 
      showToast("Message posted to your facebook wall!"); 
     } 
     finish(); 
    } catch (Exception e) { 
     showToast("Failed to post to wall!"); 
     e.printStackTrace(); 
     finish(); 
    } 
} 

class LoginDialogListener implements DialogListener { 
    @Override 
    public void onComplete(Bundle values) { 
     saveCredentials(facebook); 
     if (messageToPost != null){ 
     postToWall(messageToPost); 
    } 
    } 
    public void onFacebookError(FacebookError error) { 
     showToast("Authentication with Facebook failed!"); 
     finish(); 
    } 
    public void onError(DialogError error) { 
     showToast("Authentication with Facebook failed!"); 
     finish(); 
    } 
    public void onCancel() { 
     showToast("Authentication with Facebook cancelled!"); 
     finish(); 
    } 
} 

private void showToast(String message){ 
    Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); 
} 

} 

Neu bei Android Entwicklung so ich bin sicher, es ist etwas einfach.

+0

Was ist dein Problem? Sie können keine Nachrichten posten – TNR

+0

Nun, das ist das ultimative Ziel, aber das Problem ist, dass, wenn Facebook versucht, zurück zu meiner App zu leiten, mit dem Zugriffstoken, zeigt es die obige Nachricht. (Internetseite nicht verfügbar). Daher kann meine App das Zugriffstoken nicht erhalten und kann daher niemals autorisiert werden. – anothershrubery

+0

wird Ihre Anwendung zu Facebook-Anwendung gehen und dann stellt es nicht das Token oder es ist nicht geben Sie Token, wenn Sie von Ihrer Anwendung direkt anmelden –

Antwort

1

Ich habe die native Facebook App auf dem Gerät aktualisiert und alles funktioniert.

1

Scheint so, als ob die native Facebook App Version 2 oder höher sein muss. Ich sehe das gleiche Problem für Version 1.9.6, und ein Upgrade der Facebook-App löst das Problem.

Verwandte Themen