gpt4 book ai didi

android - 错误 #200 Facebook SDK Android

转载 作者:太空宇宙 更新时间:2023-11-03 11:15:16 24 4
gpt4 key购买 nike

亲爱的 friend 们,我正在使用 Facebook SDK 在 Android 上开发一个与 Facebook 集成的应用程序。我的应用程序应该只能发布一个链接。我使用这段代码:

this.req = new Request(session, "me/feed", b, HttpMethod.POST,
callback);

RequestAsyncTask sendRequest = new RequestAsyncTask(req);
sendRequest.execute();

使用此权限:

public static final List<String> PERMISSIONS = Arrays
.asList("publish_actions" );

实际上,在我的开发者帐户上发布链接效果很好。一旦我使用另一个帐户,我就会收到此错误消息:

(#200) The user hasn't authorized the application to perform this action

你能帮帮我吗?或者只是给个提示?

最佳答案

我认为您在 Facebook 帐户上添加的 KeyHash 允许您共享一些链接。为了能够在用户墙上发布一些东西,你必须尊重这个 facebook 的“最佳实践”:这是我的生产代码,工作正常:

private void publishStory(String hash, String title, String user) {

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(getActivity(), PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Bundle postParams = new Bundle();
postParams.putString("name", title);
postParams.putString("caption", "By Recommend Android");
postParams.putString("description", user+" "+"STRONGLY recommends"+" "+title);
postParams.putString("link", "http://re.co/"+hash);
postParams.putString("picture", "http://re.co/assets/img/useful-exp.png");

Request.Callback callback= new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
String postId = null;
try {
postId = graphResponse.getString("id");
} catch (JSONException e) {
Log.i(TAG,
"JSON error "+ e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
debug.print("erreur");
} else {
debug.print("erreur2");
}
}
};
Request request = new Request(session, "me/feed", postParams,
HttpMethod.POST, callback);

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;
}

关于android - 错误 #200 Facebook SDK Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17543999/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com