我有以下.gs代码
function updateStatus(){
var myId="100006898720726";
var myAppAccess_token="APP-ID|APP-SECRET";
var graphUrl="https://graph.facebook.com/"+myId+"/feed";
var theDate=new Date().toString();
UrlFetchApp.fetch(graphUrl,{method:"post",payload:{
message:"foo\n"+theDate,
access_token:myAppAccess_token
}});
}
和y有一个JSON网址http://pipes.yahoo.com/pipes/pipe.run?_id=a6c5eeff220e55a4fe9607065384817a&_render=json
我想在Facebook上发布每个带有说明和链接的新项目
我尝试了几种方法,但谷歌控制台总是显示错误
提前致谢
答案 0 :(得分:2)
最大的问题是您要将有效负载添加到选项中,要发布到Facebook的消息必须是Facebook URL的一部分。我在答案的底部更新了您的代码。
以下是我使用的内容:
function fncPostSecurly_(argToPost) { //argToPost is the message to post to Facebook that is passed to this function.
Logger.log("fncPostSecurly ran: " + argToPost);
var sttsUpdate = argToPost + "your text to post here" + argToPost;
var fromLogInTkn = cache.get('fbTkn'); // Get facebook token that was stored in cache
Logger.log("cache FB token: " + fromLogInTkn);
//This is added security https://developers.facebook.com/docs/graph-api/securing-requests/
var appsecret_sig = Utilities.computeHmacSha256Signature(fromLogInTkn, "YourAppSecret");
var optnPostFB = {"method" : "post"}; //
var PostToFB_URL = "https://graph.facebook.com/FacebookPageOrGroupID/feed?message=" + sttsUpdate + "&access_token="
+ fromLogInTkn;
//Make a post to the Page
var whatHappened = UrlFetchApp.fetch(PostToFB_URL, optnPostFB );
//The return from facebook is an object. Has to be converted to a string.
var strFrmFbObj = whatHappened.getContentText();
Logger.log("Return value of Post: " + strFrmFbObj);
//When a post is successfully made to Facebook, a return object is passed back with an id value.
var rtrnVerify = strFrmFbObj.indexOf('{\"id\":\"');
Logger.log("rtrnVerify: " + rtrnVerify);
if (rtrnVerify != -1) {
return true;
} else {
return false;
};
};
我认为你需要/feed
之后的问号,如下所示:
var graphUrl="https://graph.facebook.com/"+myId+"/feed?";
此外,发布到Facebook的内容是URL的一部分。您正在添加要发布到有效负载的内容。这是错误的地方。
Fetch
有两个参数。第二个参数只能是:{"method" : "post"}
你有:
{method:"post",payload:{
message:"foo\n"+theDate,
access_token:myAppAccess_token
}}
同样,您无法将有效负载添加到选项中。有效负载必须是URL的一部分。这就是Facebook使用API处理信息的方式。
function updateStatus(){
var myId="100006898720726";
var myAppAccess_token="APP-ID|APP-SECRET";
var graphUrl= "https://graph.facebook.com/" + myId+ "/feed?message=" + "foo\n" + theDate + "&access_token="
+ myAppAccess_token;
var theDate=new Date().toString();
var optnPostFB = {"method" : "post"};
UrlFetchApp.fetch(graphUrl, optnPostFB);
}
答案 1 :(得分:0)
publish_actions
权限的用户令牌才能发布到用户个人资料publish_actions
最初仅适用于在App(管理员,开发人员,测试人员)中具有角色的用户。如果你想上市,你必须首先通过review process。有关Facebook登录的信息:https://developers.facebook.com/docs/facebook-login
这是Facebook上实际允许的解决方案,甚至不需要用户授权:https://developers.facebook.com/docs/sharing/reference/share-dialog