开发者

Creating a custom Wall Post with Facebook API on Android

开发者 https://www.devze.com 2023-01-25 07:41 出处:网络
I\'m new to Facebook API on Android, and basically, what I\'m trying to do is creating custom wall post for an application I\'m developing.

I'm new to Facebook API on Android, and basically, what I'm trying to do is creating custom wall post for an application I'm developing. Like when you listen a Shazam a song and you 开发者_运维知识库can share the result with your friends. I believe I've got to create a custom attachment. Here's my code for setting the attachment:

mPostButton.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        Bundle myParams = new Bundle();
        String attachment="{\"name\":\"Gran Turismo 5\"," +
           "\"href\":\"http://www.unknown.com/?lang=fr\"," +
           "\"caption\":\"Sony Computer Entertainment\",\"description\":" +
           "\"Une vidéo proposée par Cedemo.\",\"media\":" +
           "[{\"type\":\"image\",\"src\":" +
           "\"http://www.unknown.com/prepicture//thumb_title/15/15061_1.jpg\"," +
           "\"href\":\"http://www.unknown.com/?lang=fr\"}],\"properties\":" +
           "{\"Autre lien\":{\"text\":\"Cedemo\",\"href\":\"http://www.unknown.com\"}}}";
        myParams.putString("attachment", URLEncoder.encode(attachment);
        mFacebook.dialog(Option.this, "stream.publish",myParams,
                new SampleDialogListener());

And then, later on:

public class SampleDialogListener extends BaseDialogListener {

    public void onComplete(Bundle values) {
        final String postId = values.getString("post_id");
        if (postId != null) {
            Log.d("Facebook-Example", "Dialog Success! post_id=" + postId);
            mAsyncRunner.request(postId,values, new WallPostRequestListener());
        } else {
            Log.d("Facebook-Example", "No wall post made");
        }
    }
}

I didn't wrote the attachment String, It's just a test taken from another question made in this forum. Anyway, when I call myAsync.request, my app shows an error message, how am I supposed to pass the attachment to my dialog? Hope I've been clear enough.


Are you sure you need to set custom parameters? It sounds like you can just want to post a Facebook message directly to the wall: you can do this by simply handing in the message parameter as a string -- you only need all that JSON if you want to attach an image etc. And note on facebook's page it says using this api call won't post a status update that others can see on their feed, it will just appear on their own wall. If you just want to post a message with a link you should just be able to use your mAsyncRunner (once you have your valid Facebook session) using this:

String message = "Post this to my wall";
Bundle parameters = new Bundle();        
parameters.putString("message", message);   
mAsyncRunner.request("me/feed", parameters, "POST", new WallPostRequestListener());

Also may help if you posted the error/response code you're getting from Facebook.

0

精彩评论

暂无评论...
验证码 换一张
取 消