4

我在尝试使用 Android 中的 Facebook api 向朋友墙发帖时遇到了很多麻烦。这就是我目前所拥有的:

if (facebook.isSessionValid()) {
                        String response = facebook.request((userID == null) ? "me" : userID);

                        Bundle params = new Bundle();
                        params.putString("message", "put message here");
                        params.putString("link", "http://mylink.com");    
                        params.putString("caption", "{*actor*} just posted this!");
                        params.putString("description", "description of my link.  Click the link to find out more.");
                        params.putString("name", "Name of this link!");
                        params.putString("picture", "http://mysite.com/picture.jpg");

                        response = facebook.request(((userID == null) ? "me" : userID) + "/feed", params, "POST");       

                        Log.d("Tests",response);
                        if (response == null || response.equals("") || 
                                response.equals("false")) {
                            Log.v("Error", "Blank response");
                        }
                    } else {
                        // no logged in, so relogin
                        Log.d("1234567890", "sessionNOTValid, relogin");

                    }
                }catch(Exception e){
                    e.printStackTrace();
                }

但这会返回此错误:

12-11 21:34:06.604: D/FACEBOOK RESPONSE(14954): {"error":{"message":"(#200) Feed story publishing to other users is disabled for this application","type":"OAuthException","code":200}}
4

2 回答 2

15

您可能最近创建了这个 Facebook 应用程序,这意味着 2013 年 2 月的重大更改已启用。

二月的重大变化包括:

移除通过 Graph API 向朋友墙发帖的功能

我们将删除通过 Graph API 向用户朋友的墙发帖的功能。具体来说,针对 [user_id]/feed 的 [user_id] 与会话用户不同的帖子,或 target_id 用户与会话用户不同的 stream.publish 调用将失败。如果您想允许人们发布到他们朋友的时间线,请调用提要对话框。通过用户提及标签或动作标签包含朋友的故事将显示在朋友的时间线上(假设朋友批准标签)。有关详细信息,请参阅此博客文章。

我们将从 2 月开始禁用此功能,如果您希望启用它(仅在 2 月之前暂时启用),请转到您的应用仪表板 > 设置 > 高级 > 禁用“2013 年 2 月重大更改”

但是,我强烈建议不要这样做,因为从 2 月开始,此功能将导致您的应用再次抛出相同的错误。

于 2012-12-12T00:14:48.203 回答
2

我有可能对您有所帮助的解决方案,我将它用于我的代码并且它工作正常..

私人无效publishFeedDialog(字符串friend_uid){

    try{
            Session mCurrentSession = Session.getActiveSession();

            SessionTracker mSessionTracker = new SessionTracker(
                    getBaseContext(), new StatusCallback() {
                        public void call(Session session, SessionState state,
                                Exception exception) {
                        }
                    }, null, false);
            String applicationId = Utility
            .getMetadataApplicationId(getBaseContext());
            mCurrentSession = mSessionTracker.getSession();

            if (mCurrentSession == null
                    || mCurrentSession.getState().isClosed()) {
                mSessionTracker.setSession(null);
                Session session = new Session.Builder(getBaseContext())
                .setApplicationId(applicationId).build();
                Session.setActiveSession(session);
                mCurrentSession = session;
            }

            if (!mCurrentSession.isOpened()) {
                Session.OpenRequest openRequest = null;
                openRequest = new Session.OpenRequest(
                        NewFriendList.this);

                if (openRequest != null) {
                    openRequest
                    .setDefaultAudience(SessionDefaultAudience.FRIENDS);
                    openRequest.setPermissions(Arrays.asList("email", "publish_actions"));
                    openRequest
                    .setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);



                    mCurrentSession.openForPublish(openRequest);
                }
            }



            if (regobj != null && friend_uid != null ) {

                final Activity activity = this;
                Bundle params = new Bundle();
                //This is what you need to post to a friend's wall
                params.putString("from", "" + regobj.MyFBID);
                params.putString("to", friend_uid);
                //up to this
                params.putString("name", "Facebook SDK for Android");
                params.putString("caption", "Build great social apps and get more installs.");
                params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
                params.putString("link", "https://developers.facebook.com/android");
                params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
                WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this, mCurrentSession, 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(activity,
                                        "Posted story, id: "+postId,
                                        Toast.LENGTH_SHORT).show();
                                } else {
                                    // User clicked the Cancel button
                                    Toast.makeText(activity, 
                                        "Publish cancelled", 
                                        Toast.LENGTH_SHORT).show();
                                }
                            } else if (error instanceof FacebookOperationCanceledException) {
                                // User clicked the "x" button
                                Toast.makeText(activity, 
                                    "Publish cancelled", 
                                    Toast.LENGTH_SHORT).show();
                            } else {
                                // Generic, ex: network error
                                Toast.makeText(activity, 
                                    "Error posting story", 
                                    Toast.LENGTH_SHORT).show();
                            }
                        }



                    }).build();
                feedDialog.show();
            }
    }catch(Exception e)
    {
        Log.d("Error", ""+e.toString());
    }
}

此代码仅适用于一个用户,如果要将其发送给多个用户,则可以使用 RequestsDialogBu​​ilder 而不是 WebDialog。

于 2013-07-31T09:37:10.067 回答