The biggest problem is that you are adding the payload to the options, and the message to be posted to Facebook must be part of the Facebook URL. I updated your code at the bottom of the answer.
Here is what I use:
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;
};
};
I think you need a question mark after /feed
, like this:
var graphUrl="https://graph.facebook.com/"+myId+"/feed?";
Also, the content to get posted to Facebook is part of the URL. You are adding the content to be posted to the payload. That's the wrong place to put it.
Fetch
takes two parameters. The second parameter can only be: {"method" : "post"}
You've got:
{method:"post",payload:{
message:"foo\n"+theDate,
access_token:myAppAccess_token
}}
Again, you can't add the payload to the options. The payload must be part of the URL. That's how Facebook processes the info using the API.
Updated code:
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);
}