无法打开facebook的会话

时间:2013-02-14 13:40:09

标签: android android-facebook

我使用this tutotial

制作FBLogin演示版

代码在这里//MainActivity.java

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // start Facebook Login
    Session.openActiveSession(this, true, new Session.StatusCallback() {

        // callback when session changes state
        @Override
        public void call(Session session, SessionState state,
                Exception exception) {

            Log.v("log_tag", "Token=" + session.getAccessToken());
            Log.v("log_tag", "Token=" + session.isOpened());

            if (session.isOpened()) {

                // make request to the /me API
                Request.executeMeRequestAsync(session,
                        new Request.GraphUserCallback() {

                            // callback after Graph API response with user
                            // object
                            @Override
                            public void onCompleted(GraphUser user,
                                    Response response) {
                                if (user != null) {
                                    TextView welcome = (TextView) findViewById(R.id.welcome);
                                    welcome.setText("Hello "
                                            + user.getName() + "!");
                                }
                            }
                        });
            }
        }
    });

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Session.getActiveSession().onActivityResult(this, requestCode,
            resultCode, data);
}
}

//的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fbdemo"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="8" />

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.fbdemo.MainActivity"
        android:label="@string/app_name" >
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name="com.facebook.LoginActivity" />

    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/app_id" />
</application>

</manifest>
<{1}}中的

输出就像这样

log_cat
请告诉我问题出在哪里?

1 个答案:

答案 0 :(得分:1)

问题在于生成了散列密钥。有时可能会生成错误的密钥。所以检查密钥然后再试一次。当我换了钥匙时,问题就解决了。