我一直在修改一个让 Facebook 喜欢的脚本来获取 Facebook 见解。此脚本按城市获取用户的独特页面印象,并将它们全部显示在一个单元格中。
问题: 有什么方法可以将其分解为多个单元格?我尝试在工作表上附加一行,但它告诉我我没有权限
代码:
////
// Facebook Fans Counter
// Made by Martin Hassman, http://twitter.com/hassmanm
// Released as Public Domain
// Look at http://labs.met.cz/ for other tools
// Edit by Jared Beach
//
function FacebookListOf(aPageId,aToken,aParameter)
{
if (aPageId === undefined || aPageId === null)
{
throw "No parameter specified. Write Facebook PageID as parameter."
}
if (aToken === undefined || aToken === null)
{
throw "No parameter specified. Write Facebook Access Token as parameter."
}
if (aParameter === undefined || aParameter === null)
{
throw "No parameter specified. Write Facebook Access Token as parameter."
}
var today = new Date();
today.setDate(today.getDate()-6);
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm} today = yyyy+'-'+mm+'-'+dd;
if (typeof aPageId != "number")
throw "Parameter must be number.";
// See http://developers.facebook.com/docs/reference/fql/page/ for API documentation
var url = "https://api.facebook.com/method/fql.query?query=SELECT%20metric,%20value%20FROM%20insights%20WHERE%20object_id=%22"+ encodeURIComponent(aPageId) + "%22%20AND%20metric=%27"+ encodeURIComponent(aParameter) + "%27%20AND%20end_time=end_time_date%28%27"+ encodeURIComponent(today) +"%27%29%20AND%20period=period%28%27day%27%29%20&%20access_token=" + encodeURIComponent(aToken);
var response = UrlFetchApp.fetch(url);
if (response.getResponseCode() != 200)
throw "Unexpected response code from Facebook.";
var responseText = response.getContentText();
if (responseText == null || responseText == "")
throw "Empty response from Facebook.";
var value;
try
{
var xml = Xml.parse(responseText, false);
var page = xml.getElement().getElement();
if (page == null)
throw "Wrong PageID.";
value = page.getElement("value").getElements("insMap");
/*
var format2 = value.toXmlString();
return format2;
*/
if (!value || value.length ==0) {
throw "no match found";
}
}
catch (e)
{
throw "Problem with response from Facebook: " + e;
}
var r ="";
var listLength = value.length;
for (var i = 0; i < listLength; i ++){
r = r + value[i].getAttribute("key").getValue() + " : " + value[i].getText() + "\n";
}
return r;
}
**结果截图:**