4

亲爱的朋友们,我正在使用 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

你能帮我么?还是只是给个提示?

4

1 回答 1

0

我认为您在 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;
}
于 2013-07-09T09:08:52.150 回答