我正在尝试将 Facebook **集成到我的Android应用中。我想在** facebook 上实现**喜欢和分享**设施。但我收到了错误。
请帮我解决这个问题。
此外,我想知道在Facebook上创建新应用程序的过程。
我正在使用 GitHub 中的代码。我的代码是 -
public class MyGreatActivity extends Activity {
Facebook facebook = new Facebook("333778590046892");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
facebook.authorize(this, new String[] { "offline_access", "publish_stream", "raj21kadam@gmail.com" },
new DialogListener() {
@Override
public void onComplete(Bundle values) {
String token=facebook.getAccessToken(); //get access token
// Toast.makeText(this, "token", Toast.LENGTH_LONG).
save(token);
}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
private void save(String token){
Toast.makeText(this, "token"+token, Toast.LENGTH_LONG).show();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putString("Token", token).commit();
}
}
运行上面的代码时出现以下错误 -
Dialog Errorcom.facebook.android.DialogError: The connection to the server was unsuccessful.
答案 0 :(得分:1)
试试这个Single Sign On (SSO) Using Android Native Client For Facebook 。 粘贴这个
facebook.authorize(this, new DialogListener() {
@Override
public void onComplete(Bundle values) {
String token=facebook.getAccessToken(); //get access token
// Toast.makeText(this, "token", Toast.LENGTH_LONG).
save(token);
}
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
}
而不是
facebook.authorize(this, new String[] { "offline_access", "publish_stream", "raj21kadam@gmail.com" },
new DialogListener() {
@Override
public void onComplete(Bundle values) {
String token=facebook.getAccessToken(); //get access token
}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
}