我无法在facebook的最新版本的android中打开一个会话。当我调试我的代码时,它会显示会话状态:“OPENING” - >没开”。我在这个问题上堆了几天,互联网上没有这样的问题,所以请帮助我。 这是我的主要类:
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>
答案 0 :(得分:6)
伙计我可以成为在stackoverflow中告诉它后立即解决问题的最快的人。问题是:我在清理其他愚蠢的尝试代码时删除了一个被覆盖的函数。我再次将它添加到我的主要课程中:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}