将 Facebook SDK 集成到 android 时遇到问题。基本上,我已经成功集成到我的手机中。我按照教程添加了具有 30 长度字符串的哈希键。然后在我的设备上测试它工作正常。
然而,当我让我的朋友试用我的应用程序时,他报告说他无法对分享 facebook 的东西做任何事情。这是执行共享内容的代码块:
/**
* Publish Feed Dialog
* @param current
* @param title
* @param caption
* @param description
* @param link
* @param pictureUrl
*/
public static void publishFeedDialog(final Activity current, final String title, final String caption, final String description, final String link, final String pictureUrl) {
// start Facebook Login
Session.openActiveSession(current, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Bundle params = new Bundle();
params.putString("name", title);
params.putString("caption", caption);
params.putString("description", description);
if (link != null) params.putString("link", link);
if (pictureUrl != null) params.putString("picture", pictureUrl);
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(current, Session.getActiveSession(), params))
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
// When the story is posted, echo the
// success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(current, "Posted", 2000).show();
} else {
// User clicked the Cancel button
Toast.makeText(current, "Publish cancelled", 2000).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(current, "Publish cancelled", 2000).show();
} else {
// Generic, ex: network error
Toast.makeText(current, "Error posting story", 2000).show();
}
}
}).build();
feedDialog.show();
}
}
});
}
我只使用这段代码来发布提要对话框。对于 facebook 应用程序设置:
- 包名称-> com.ImranQureshi.HadithPro
- 类名 -> com.imran.hadith.MainActivity
- 密钥哈希 -> t8tk8tRXcAXxnn4U0mRcCBSqHf
- Facebook 登录 -> 已启用
- 深度链接 -> 禁用
如果我不使用密钥哈希,我会在那里得到异常,它说:com.facebook.http.protocol.ApiException: Key hash t8tk8tRXcAXxnn4U0mRcCBSqHf does not match any stored key hashes
这是有道理的,因为哈希不存在。当我放置该哈希键时,它可以在我的真实设备中使用,但不能在我朋友的设备中使用。你能建议什么是错的吗?