0
votes

I am using google apps script and posting on facebook via facebook api. But don't know how to format this in google apps script so that it works. When i copy and paste this on browser url then it's working fine but on google apps script it's throwing error.

This works on Browser Url: https://graph.facebook.com/209945086121853/photos?access_token=MyAccessToken&caption=Blue%20Cotton%20Voile%20Basic%201-Piece%20Kacha%20Tanka%20Collection%20Kurti%20for%20Women%20-%20Generation%20-%20COD&url=http://5.gp/qzgb&feed_targeting={genders:[2]}&include_headers=false&method=POST

But in Google apps my this code not working.

var options = {
    "method" : "post"  
                    }; 
        
      message = AEData[p][AEProductName];
      PostPic = "http://example.com/mypic.jpg"; 
      var  batchPost = "https://graph.facebook.com/mypageid/photos?access_token=myAccessToken&caption=" + encodeURIComponent(message) + "&url=" + PostPic + "&feed_targeting={genders:[2]}" + "&include_headers=false";
      var FBPost = UrlFetchApp.fetch(batchPost,options);

Error is Invalid Parameter

1

1 Answers

0
votes

It was encoding issue "&feed_targeting=" + encodeURIComponent("{genders:[2]}") solve my problem.