简体   繁体   English

FACEBOOK JS SDK ::如何在墙上发布图像

[英]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 我试图将图像发布到我的用户的Facebook墙上,一旦他们碰到了按钮

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 我正在使用JavaScript SDK,但我有一个问题,图像看起来像墙上的链接...但这不是我想要的...我想发布图像...与你放一个图像链接相同在您的状态文本字段上,它将变为图像

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', 
                            '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: 试试FB.api()方法:

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. 要在用户墙上发布图像,请使用FB.api('/ me / photos',...)而不是FB.api('/ me / feed',...),此外还需要访问令牌。

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" . 在朋友页面上发帖:输入朋友的facebook用户ID代替“/ me”。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM