1

我已经使用这个教程制作了 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>

输出log_cat是这样的

02-14 19:08:25.251: V/log_tag(1558): Token=
02-14 19:08:25.251: V/log_tag(1558): Token=false
02-14 19:08:38.834: V/log_tag(1558): Token=
02-14 19:08:38.834: V/log_tag(1558): Token=false

请告诉我问题出在哪里?

4

1 回答 1

1

问题在于生成的哈希键。有时可能会生成错误的键。因此,请检查密钥并重试。当我更改密钥时,问题为我解决了。

于 2014-05-18T09:41:59.590 回答