How can I post text on a friend's wall using the android facebook sdk
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.
This is the code I am using:
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());
}
}
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.
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.
Thank you!
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:
Check out my answer here: Post on user's friends facebook wall through android application
精彩评论