将电子邮件发布到Facebook自定义观众

我正尝试使用以下来自文档的卷曲将电子邮件列表插入Facebook自定义观众:

 curl 
-F 'payload={ 
 "schema": "EMAIL_SHA256", 
   "data": [
    "9b431636bd164765d63c573c346708846af4f68fe3701a77a3bdd7e7e5166254",
    "8cc62c145cd0c6dc444168eaeb1b61b351f9b1809a579cc9b4c9e9d7213a39ee",
    "4eaf70b1f7a797962b9d2a533f122c8039012b31e0a52b34a426729319cb792a" 
    ]
  }' 
-F 'access_token=<ACCESS_TOKEN>' 

通过ads_management接收到有效的访问令牌后,我的代码如下:

  class Payload
    {
        public Payload(List<string> strings)
        {
            schema = "EMAIL_SHA256";
            data = new List<string>();                
            foreach (string str in strings)
            {
                data.Add(sha256(str));
            }
        }
        public string schema { get; set; }
        public List<string> data { get; set; }
    }

    class PostData
    {
        public PostData(string token, List<string> strings)
        {
            access_token = token;
            payload = new Payload(strings);
        }
        public Payload payload;
        public string access_token { get; set; }
    }  

    public async Task InsertEmails(List<string> emails, string id)
    {     
        using (var httpClient = new HttpClient())
        {
            httpClient.BaseAddress = new Uri("https://graph.facebook.com/");                
            httpClient.DefaultRequestHeaders
              .Accept
              .Add(new MediaTypeWithQualityHeaderValue("application/json"));                

            HttpRequestMessage request = new HttpRequestMessage(System.Net.Http.HttpMethod.Post, "v2.6/" + id + "/users");                
            PostData postData = new PostData(_accessToken, emails);                
            request.Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(postData),
                                Encoding.UTF8,
                                "application/json");                         
            await httpClient.SendAsync(request)
                  .ContinueWith(responseTask =>
                  {
                      Console.WriteLine("Inserting emails into Facebook Response: {0}", responseTask.Result);
                  });
        }
    }

错误是:

OAuth “Facebook Platform ”“invalid_request ”“不支持的发布请求。ID为的对象不存在,由于缺少权限而无法加载,或者不支持此操作。 https://developers.facebook.com/docs/graph-api

可能是什么原因? 访问令牌和受众ID似乎都是正确的。


事实证明,代码本身没有任何问题,我会离开它,以防有人需要它。

问题出在访问令牌上。 对于Facebook Marketing API,即使您设置scope = ads_management也无法以编程方式获取访问令牌。

您需要首先通过Web界面接收短暂的令牌。

然后拥有这个短暂的令牌,如果有必要,您可能会获得60天的长期有效令牌。

确保Marketing API具有ads_management权限。

链接地址: http://www.djcxy.com/p/32561.html

上一篇: Posting emails into facebook custom audience

下一篇: Unsupported get request