Javascript FACEBOOK JS SDK ::如何在墙上张贴图片
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3361507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FACEBOOK JS SDK ::how to post an image on wall
提问by trrrrrrm
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.');
}
}
回答by serg
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").
您可以在此处获取支持的墙贴参数列表(请参阅“发布”)。
回答by HBK
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" ....

