开发者

FACEBOOK JS SDK ::how to post an image on wall

i'm trying to post an image to my users's facebook wall once they hit a botton

i'm using javascript SDK but i have a problem, the image looks like a link in the wall ... but that's not what i want ... i want to post an image ... same as when you put an image link on your status text field and it turns to image

any help ?

FB.ui(
           {
             method: 'stream.publish',
             message: 'test',
             attachment :{ 
                    'name': 'i\'m bursting with joy', 
                    'href': ' http://bit.ly/187gO1', 
                    'caption': '{*actor*} rated the lolcat 5 stars', 
                    'description': 'a funny looking cat', 
                    'properties': { 
                        'category': { 'text': 'humor', 'href': 'http://bit.ly/KYbaN'}, 
                        'ratings': '5 stars' 
                    }, 
                    'media': [{ 
                            'type': 'image', 
                            'src': 'http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg', 
              开发者_Python百科              'href': 'http://bit.ly/187gO1'}] 
                        },
             user_message_prompt: 'Share your thoughts about Connect'
           },
           function(response) {
             if (response && response.post_id) {
               alert('Post was published.');
             } else {
               alert('Post was not published.');
             }
           }


Try FB.api() method:

var wallPost = {
    message : "testing...",
    picture: "http://url/to/pic.jpg"
};
FB.api('/me/feed', 'post', wallPost , function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Post ID: ' + response);
  }
});

You can get a list of supported wall post params here (see "Publishing").


To POST an image in user's wall use FB.api('/me/photos',...) instead of FB.api('/me/feed',...) and additionally access token is required.

Attached is the Code Example:

FB.login(function(response) {
    if (response.authResponse) {
        var access_token =   FB.getAuthResponse()['accessToken'];
        FB.api('/me/photos?access_token='+access_token, 'post', { url: IMAGE_SRC, access_token: access_token }, function(response) {
            if (!response || response.error) {
                //alert('Error occured: ' + JSON.stringify(response.error));
            } else {
                //alert('Post ID: ' + response);
            }
        });
    } else {
        //console.log('User cancelled login or did not fully authorize.');
    }
}, {scope: 'publish_stream'});

To Post on Friends Page: Enter the facebook user Id of friends in place of "/me" .

"/"+friends_user_id+"/photos" ....
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜