我正在尝试使用Insights Edge API获取一些洞察数据,但遇到权限问题:
以下是我正在使用的代码:
string applicationId = "";
string applicationSecret = "";
string accountId = "";
System.Net.WebClient client = new System.Net.WebClient();
string accessToken = client.DownloadString("https://graph.facebook.com/oauth/access_token?client_id=" + applicationId + "&client_secret=" + applicationSecret + "&grant_type=client_credentials").Replace("access_token=","");
System.Net.WebRequest req = System.Net.WebRequest.Create("https://graph.facebook.com/v2.4/act_"+accountId+"/insights?access_token=" + accessToken);
System.Net.WebResponse response = req.GetResponse();
using(System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()))
{
string s = sr.ReadToEnd();
Console.WriteLine(s);
}
我收到了以下JSON:
{
"error": {
"message": "(#10) You do not have sufficient permissions to perform this action",
"type": "OAuthException",
"code": 10
}
}
有问题的应用程序是在与广告帐户相同的Facebook帐户下创建的。我需要检查帐户/应用程序设置,看看我是否拥有访问Ad Insights API的所有正确权限?代码需要在不需要用户干预的服务中运行,在这种情况下,应用程序访问令牌是访问广告洞察数据的正确方法吗?