我在我的 android 应用程序中使用 facebook 连接。它基本上是一种形式。页面上有一个facebook登录按钮。我希望在用户使用 Facebook 登录时填写表单上的信息。
我正在尝试以下代码:
public void loginFB() {
facebook.authorize(this, new String[] { "email", "read_stream" }, new DialogListener() {
@Override
public void onComplete(Bundle values) {}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
getlogininfo();
}
public void getlogininfo(){
mAsyncRunner.request("me", new RequestListener(){
@Override
public void onComplete(String response, Object state) {
try{
Log.d("Profile", response.toString());
JSONObject json = Util.parseJson(response);
final String fname1 = json.getString("first_name");
final String lname1 = json.getString("last_name");
final String email = json.getString("email");
MintPaymentsActivity.this.runOnUiThread(new Runnable(){
public void run() {
fname.setText(fname1);
lname.setText(lname1);
emailadd.setText(email);
}
});
}
catch(JSONException e){
Log.w("This", "eror");
}
}
@Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFileNotFoundException(FileNotFoundException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onMalformedURLException(MalformedURLException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
});
}
/*FB --- */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
基本上,当用户单击按钮时,facebook 会要求登录,然后收集 JSON 数据以显示登录用户的姓名和电子邮件。
它给了我以下错误:
05-30 21:52:40.598: E/AndroidRuntime(665): FATAL EXCEPTION: Thread-13
05-30 21:52:40.598: E/AndroidRuntime(665): com.facebook.android.FacebookError: An active access token must be used to query information about the current user.
05-30 21:52:40.598: E/AndroidRuntime(665): at com.facebook.android.Util.parseJson(Util.java:279)
05-30 21:52:40.598: E/AndroidRuntime(665): at com.Myapp.Myapp$2.onComplete(Myapp.java:117)
05-30 21:52:40.598: E/AndroidRuntime(665): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:254)
当我放置一个额外的按钮来填写详细信息时,以便在getlogininfo()
单击按钮时实现(登录后)它工作正常。但我希望在用户单击 facebook 登录按钮后立即填写。