简体   繁体   English

使用Javascript和Facebook Graph API

[英]Using Javascript and Facebook Graph API

I'm trying to publish to another user wall, so it would appear as if HE published this post himself. 我正在尝试发布到其他用户墙上,因此好像HE亲自发布了此帖子一样。 For example, I want to write "I've published a new article on Youngo.com" on his wall. 例如,我想在他的墙上写“我在Youngo.com上发表了一篇新文章”。

I have an offline access and stream publish permissions. 我具有脱机访问权限和流发布权限。 I also got the access token. 我也获得了访问令牌。 I just can't figure how to do that using JavaScript. 我只是不知道如何使用JavaScript做到这一点。

Do you mean something like this: 您的意思是这样的吗:

var wallPost = {
    access_token: "<ACCESS_TOKEN>",
    message: 'Hello, World!'
};

FB.api('/<UID>/feed', 'post', wallPost, function(response) {
    if (!response || response.error) {
        alert('Error occurred');
    } else {
        alert('Success!');
    }
});

If you are trying to post to FB's API directly from javascript it won't work. 如果您尝试直接从javascript发布到FB的API,它将无法正常工作。 You have to wrap their api with a web service on your domain since javascript isn't allowed to do cross domain requests. 您必须使用域上的网络服务包装他们的api,因为不允许javascript进行跨域请求。

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

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