我正在关注本教程https://developers.facebook.com/docs/android/getting-started/
但是当我启动我的应用时出了点问题。一些启动后,AlertDialog问我,我的应用程序需要访问我的公开个人资料,没有出现,并且onCompleted方法永远不会被解雇
public class MainActivity extends Activity {
String TAG = "FACEBOOK";
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_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.i(TAG,
"openactivesession ,call with state "
+ state.toString());
if (session.isOpened()) {
Log.i(TAG, "Session is opened");
// make request to the /me GRAPH API that retrieve info
// about ME
Request.newMeRequest(session, new Request.GraphUserCallback() {
// callback after Graph API response with user
// object
@Override
public void onCompleted(GraphUser user, Response response) {
Log.i(TAG, "inside onCompleted");
if (user != null) {
Log.i(TAG, "user not null");
tv = (TextView) findViewById(R.id.tv);
tv.setText("Hello "+ user.getFirstName() + " "+ user.getName());
}
}
});
}
}
});
}
/*
* onAcitvityResult is called when we start an activity to get a result
* (with startActivityForResult() ). After started activity ends, return his
* result as Intent (third args)
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode,
resultCode, data);
}
}
清单
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="20" />
<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.firstandroidapp.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>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id" />
<activity android:name="com.facebook.LoginActivity" />
</application>
我不知道会出现什么问题。我也尝试生成一个新的哈希值,但仍然无法正常工作
答案 0 :(得分:1)
在 Reqest.newMeRequest
之后添加代码 .executeAsync(); Request.newMeRequest(session, new GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
// Your code here
}
}).executeAsync();