首页 > 解决方案 > 如何在 Google App 脚本中使用 UrlFetch 获取 Facebook 页面提要的内部字段?

问题描述

我正在尝试通过 Google App 脚本中的 urlfetch 函数获取 facebook 页面提要 json 数据的内部字段,但我得到了

无效的论点

错误。我看到了其他一些解决方案,但在我的情况下它们都不起作用这是我的代码我正在尝试获取附件内部字段,例如 fields=attachments{subattachments,url} 大括号是这里的问题,那么如何通过 urlfetchApp 解析它?

var url = 'https://graph.facebook.com'
+ '/pageneme/feed'
+'?fields=name,full_picture,message,attachments{subattachments,url}&access_token=MYACCESStoken'



var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});

var json = response.getContentText();
var jsondata = JSON.parse(json);

var data =jsondata.data
var pagename =data[0].name
var images= data[0].full_picture
var messages =data[0].message
    var attachment = data[0].attachments 

var media =data[0].subattachments


Logger.log(images);  //check this and adjust following for loop and html 
showFeed function accordingly
 Logger.log(messages);
Logger.log(attachment);

标签: facebook-graph-apigoogle-apps-scripturlfetch

解决方案


自己得到它感谢那些投反对票的人

我的网址中有不安全的字符。我必须对网址进行编码:

 var url = 'https://graph.facebook.com'
+ '/pagename/feed'
//   + '?access_token=' + encodeURIComponent(getToken());
+'?fields='+ 
encodeURIComponent("name,full_picture,message,attachments{subattachments,url}")

+'&access_token=token'

推荐阅读