我在 Play 商店有一个应用程序,最近我用新的 Facebook 3 SDK 更新了它,我想要与 Facebook 集成做的就是用户可以将我的应用程序中的单词/字符串发布到 Facebook 墙。我按照 Facebook“开始”和我下载的示例中的说明编写代码,我使用 Eclipse->properties->android->add library-> 导入库并选择 Facebook SDK(如 Facebook dev 中所述)。该应用程序与我自己的星系 S3 和 S1 直接从 eclipse 中运行非常好,它可以正确登录并毫无问题地发布在我的墙上!
在我像往常一样签署应用程序并将其重新发布到 Play 商店后,问题就开始了!我不能在 Facebook 上登录/发帖,当然,用户也不能发帖。
尝试运行签名的应用程序时出现此错误:
com.facebook.orca.protocol.base.ApiException: remote_app_id does not match stored id
我开始寻找解决方案,所有答案都是关于“keyhash”..我添加了 2 个 keyhash,如此处Stackoverflow (debug +release key).. 并且还得到了一个 keyhash,其中包含上一个链接中第 3 号答案中提到的代码,尝试过Facebook开发仪表板中的不同设置..“app id”/app_id也是正确的,但没有成功!!
当我尝试使用 Eclipse 的应用程序时一切正常,如果应用程序未登录,则没有帖子。
这是我的代码,也许我错过了什么,两天后我真的很困惑没有解决方案
public class main extends Activity {
private Session.StatusCallback statusCallback = new SessionStatusCallback();
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
@SuppressWarnings("unused")
private boolean pendingPublishReauthorization = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//this code was for test
try {
PackageInfo info = getPackageManager().getPackageInfo(
"mypackage here",
PackageManager.GET_SIGNATURES);
for (android.content.pm.Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
buttonLoginLogout = (ImageView)findViewById(R.id.buttonLoginLogout);
post = (ImageButton)findViewById(R.id.fbshare);
Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
Session session = Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
}
if (session == null) {
session = new Session(this);
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
}
}
updateView();
post.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
publishStory();
}
});
}
@Override
public void onStart() {
super.onStart();
Session.getActiveSession().addCallback(statusCallback);
}
@Override
public void onStop() {
super.onStop();
Session.getActiveSession().removeCallback(statusCallback);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Session session = Session.getActiveSession();
Session.saveSession(session, outState);
}
private void updateView() {
Session session = Session.getActiveSession();
if (session.isOpened()) {
buttonLoginLogout.setImageResource(R.drawable.fblogout);
buttonLoginLogout.setOnClickListener(new OnClickListener() {
public void onClick(View view) { onClickLogout(); }
});
post.setVisibility(View.VISIBLE);
} else {
buttonLoginLogout.setImageResource(R.drawable.fblogin);
buttonLoginLogout.setOnClickListener(new OnClickListener() {
public void onClick(View view) { onClickLogin(); }
});
post.setVisibility(View.INVISIBLE);
}
}
private void onClickLogin() {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
} else {
Session.openActiveSession(this, true, statusCallback);
}
}
private void onClickLogout() {
Session session = Session.getActiveSession();
if (!session.isClosed()) {
session.closeAndClearTokenInformation();
}
}
private class SessionStatusCallback implements Session.StatusCallback {
public void call(Session session, SessionState state, Exception exception) {
updateView();
}
}
private void publishStory() {
Session session = Session.getActiveSession();
if (session != null){
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Request request = Request.newStatusUpdateRequest(Session.getActiveSession(), messege, new Request.Callback() {
public void onCompleted(Response response) {
Toast.makeText(main.this, "messege sent..", Toast.LENGTH_SHORT).show();
}
});
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
}
private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
for (String string : subset) {
if (!superset.contains(string)) {
return false;
}
}
return true;
}
}
请帮助..这是我的第一篇文章,我希望能找到答案:-)
另一个问题,也许它会解决问题:我是否必须等待 facebook 批准我的应用程序或无关紧要?
谢谢