我在我的应用程序中设置了与 fb 的连接:单击应用程序进行登录的按钮,在墙上发帖,然后注销。使用我的开发者帐户,一切对我来说都很完美,但尝试使用其他手机和其他帐户,如果安装了官方 FB 应用程序,该应用程序不会发布任何内容。我刚刚更改了密钥哈希,我没有使用 debug.keystore 而是一个新的密钥库.....任何人都可以帮助我???? 非常感谢!
我按照fb的教程,这是我的登录方法
private void onClickLogin() {
Session session = Session.getActiveSession();
login=true;
if (session!=null && !session.isOpened() && !session.isClosed()) {
session.openForPublish(new Session.OpenRequest(this)
.setPermissions(Arrays.asList("publish_actions"))
.setCallback(callback));
} else {
Session.openActiveSession(getActivity(), this, true, callback);
}
}
这是所有“有趣”的代码
boolean login= false;
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
private UiLifecycleHelper uiHelper;
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
private static final String PENDING_PUBLISH_KEY = "pendingPublishReauthorization";
private boolean pendingPublishReauthorization = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}
public void setEnt(Entry e) {
art=e;
}
@Override
public void onResume() {
super.onResume();
Session session = Session.getActiveSession();
uiHelper.onResume();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
private void onClickLogin() {
Session session = Session.getActiveSession();
login=true;
if (session!=null && !session.isOpened() && !session.isClosed()) {
session.openForPublish(new Session.OpenRequest(this)
.setPermissions(Arrays.asList("publish_actions"))
.setCallback(callback));
} else {
Session.openActiveSession(getActivity(), this, true, callback);
}
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
publishStory();
} else if (state.isClosed()) {
}
}
private void publishStory() {
Session session = Session.getActiveSession();
if(login){
if (session != null){
Bundle postParams = new Bundle();
postParams.putString("name", art.getTitle());
postParams.putString("caption", art.getSection());
postParams.putString("description", "xxx");
postParams.putString("link", "xxx");
postParams.putString("picture", "xxx");
Request.Callback callback= new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
String postId = null;
try {
postId = graphResponse.getString("id")+" articolo postato";
} catch (JSONException e) {
Log.i(TAG,
"JSON error "+ e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(getActivity()
.getApplicationContext(),
error.getErrorMessage(),
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity()
.getApplicationContext(),
postId,
Toast.LENGTH_LONG).show();
logout();
}
}
};
Request request = new Request(session, "me/feed", postParams,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
Log.v("FB", "FINE");
}
}
}
private void logout(){
login=false;
if (Session.getActiveSession() != null) {
Session.getActiveSession().closeAndClearTokenInformation();
}
Session.setActiveSession(null);
}
private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
for (String string : subset) {
if (!superset.contains(string)) {
return false;
}
}
return true;
}
}