2
我無法在Android中的Facebook最新sdk中打開會話。當我調試我的代碼時,它顯示會話狀態:「OPENING」 - >「OPEN」。我在這個問題上堆了幾天,在互聯網上沒有這樣的問題,所以請幫助我。 這裏是我的榜樣主類:無法在Android中的Facebook中打開會話
public class Miranda extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView userNameView = (TextView) findViewById(R.id.userName);
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
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) {
userNameView.setText("Hello " + user.getName() + "!");
// profilePictureView.setProfileId(user.getId());
}
}
});
}
}
});
}
}
這裏是AndroidManifest.xml中:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.Miranda"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"/>
<application android:label="@string/app_name">
<activity android:name="Miranda"
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"
android:label="@string/title_facebook_login">
</activity>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
,最後的strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Miranda</string>
<string name="app_id">241765162664333</string>
<string name="title_facebook_login">Log Into Facebook</string>
</resources>