我删除了下面的.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 URL http://pipes.yahoo.com/pipes/pipe.run?_id=a6c5eeff220e55a4fe9607065384817a&_render=json
我想发布到facebook的每一个新项目的描述和链接
我尝试过几种方法,但google控制台总是显示错误
提前感谢
发布于 2014-12-07 05:51:34
最大的问题是,您正在将有效负载添加到选项中,并且要发布到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);
}发布于 2014-12-07 04:57:16
publish_actions权限的用户令牌才能发布到用户profilepublish_actions最初只适用于在应用程序中具有角色(管理员、开发人员、测试人员)的用户。如果你想公开消息,你必须先通过review process。,请参阅platform policy
关于脸书登录的信息:https://developers.facebook.com/docs/facebook-login
这里有一个解决方案,实际上在Facebook上是允许的,甚至不需要用户授权:
https://stackoverflow.com/questions/27336281
复制相似问题