如何使用android facebook sdk在朋友的墙上发布文字?

问题描述:

我正在尝试使用Android Facebook sdk在用户的朋友的墙上发帖。我已经使用类似的电话成功发布到用户自己的新闻Feed。使用我当前的代码,发送给朋友的工作没有任何障碍,除了消息是空白的。没有附件似乎工作。它在朋友的墙上显示为一个完全空白的帖子。

I am trying to use the Android Facebook sdk to make a post on the user's friend's wall. I have successfully posted to the user's own news feed using similar calls. With my current code, the post to a friend works without a hitch, except that the message is blank. None of the attachments seem to work. It shows up as a completely blank post on the friend's wall.

这是我使用的代码:

private void publishChallengeToFriend() {
    String description = 
        "I challenge you to " + m_challenge.getTitle() + "!" + 
        " I finished this challenge with a score of " + getScore() + "."
        + " Can you beat that?";

    Bundle params = new Bundle();
    params.putString(Facebook.TOKEN, m_facebook.getAccessToken());
    params.putString("message", "");
    params.putString("name", "You have been challenged!");
    params.putString("caption", "Mobile Challenges");
    params.putString("description", description);
    try{
    m_facebook.request(getFriendId() + "/feed",params, "POST");
    }
    catch (Exception e){
        Log.d("TAG", "Facebook Error: " + e.getLocalizedMessage());
    }
}

我已经授权用户,我知道因为我可以发布到用户自己的Feed。我知道 https://github.com/facebook上的github问题#166 / Facebook的Android的SDK /问题/ 166 。我已经尝试通过在每个要传输的字符串上调用getBytes()来为每个附件使用putByteArray()。这仍然显示为朋友墙上的空白信息。

I have already authorized the user, and I know that works because I can post to the user's own feed. I am aware of the github issue #166 at https://github.com/facebook/facebook-android-sdk/issues/166. I have tried using putByteArray() for each of the attachments by calling getBytes() on each string I would like to transmit. This still shows up as a blank post on the friend's wall.

我可以使用任何方式发布在朋友的墙上,它不一定是Facebook的要求。我也使用asyncfacebookrunner.request()并且有同样的问题。理想情况下,我想使用一个对话框来显示这个,但我不知道如何使用对话框()函数的朋友的帖子。不过,我使用它来进行状态更新。

I am open to using any method of posting on the friend's wall, it doesn't have to be a facebook request. I have also used asyncfacebookrunner.request() and have had the same problem. Ideally, I would like to use a dialog to show this, but I have no idea how to use the dialog() function for friend posts. I use that for status updates without a hitch, however.

谢谢!

您正在将消息作为描述,尝试将其移动到消息参数中,description参数是您放在帖子中并将显示在链接下的链接的描述。它不会显示在你的帖子,因为你没有链接任何东西!您可以在下面看到我的方法:

You are putting the message as the description, try moving it to the message parameter, the "description" parameter is a description of a link that you put in the post and will appear under the link. It wont show on your post because your not linking anything! You can see my method for doing it below:

protected void postToWall(String userID){
    try {
        if (isSession()) {
            String response = mFacebook.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 = mFacebook.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(TAG, "sessionNOTValid, relogin");
            mFacebook.authorize(this, PERMS, new LoginDialogListener());
        }
    }catch(Exception e){
        e.printStackTrace();
    }
}

这是结果,所以你可以看到不同的参数出现在帖子上:

this is the result so you can see where the different parameters appear on the post: