Facebook的整合在Android fbconnect断开链接 [英] Facebook integration on Android fbconnect broken link

查看:276
本文介绍了Facebook的整合在Android fbconnect断开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现的Facebook融入我的Andr​​oid应用程序,它熄灭,并登录到Facebook的很好,但是当它试图通过访问令牌回到它只是返回应用程序:

I am trying to implement Facebook integration into my Android app and it goes off and logs in to Facebook fine, but when it tries to pass the access token back to the app it just returns:

在fbconnect的网页://成功#access_token = [访问令牌]   可能暂时无法连接,或者它已永久性地移动到一个新的   Web地址。

The webpage at fbconnect://success#access_token=[ACCESS TOKEN] might be temporarily down or it may have moved permanently to a new web address.

显然,其中 [访问令牌] 是一个长期的字符序列。

Obviously where [ACCESS TOKEN] is a long sequence of chars.

我已经得到了应用程序ID正确,并且增加了密钥散列到Facebook。但过程可能我错过了什么?

I have got the App ID correct and added the key hash to facebook. But what process could I have missed?

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();
}

}

新到Android的发展,所以我敢肯定,这是简单的东西。

New to Android development so I'm sure it's something simple.

推荐答案

好像天然的Facebook应用程序必须是版本2或者更高。我看到了同样的问题为1.9.6版本,升级Facebook应用程序解决了这个问题。

Seems like the native Facebook App must be version 2 or higher. I am seeing the same issue for 1.9.6 version, and upgrading the Facebook app solves the issue.

这篇关于Facebook的整合在Android fbconnect断开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆