在 facebook 营销 api leadgen_context_cards 边缘不接受 cover_photo
In facebook marketing api leadgen_context_cards edge is not accepting cover_photo
我正在关注 https://developers.facebook.com/docs/marketing-api/guides/lead-ads/create/v2.8 以创建线索广告的背景卡片。文档说它将接受 cover_photo 字段。
但是,如果我们尝试使用以下参数
从 Graph API Explorer 创建上下文
https://developers.facebook.com/tools/explorer/xxxxxx?method=POST&path=<PAGE_ID>%2Fleadgen_context_cards&version=v2.8&title=sample-title-1&style=PARAGRAPH_STYLE&content=[%22sample%20content%201%22]&button_text=Get%20Started&cover_photo=http://xxxxx.s3.amazonaws.com/sample/sampleimage.png
显示以下内容
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1,
"fbtrace_id": "xxxxxx"
}
}
如果我们点击 fgtrace_id 它会显示以下内容
{
"error": {
"message": "(#803) Some of the aliases you requested do not exist: xxxxx",
"type": "OAuthException",
"code": 803,
"fbtrace_id": "yyyyyy"
}
}
如果我们删除 cover_photo
参数,我们就能够创建上下文卡片。
谢谢。
更新 1
我试过上传实际的图像文件。仍然面临同样的问题。以下是代码和响应。
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httppost = new HttpPost(GRAPH_FACEBOOK_LEADGEN_CONTEXT_CARDS);
File file = new File(IMAGE_PATH);
ContentBody cbFile = new FileBody(file, ContentType.create(MimeTypeUtils.IMAGE_PNG_VALUE));
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("access_token", ACCESS_TOKEN);
builder.addTextBody("title", "sample-title-1");
builder.addTextBody("style", "PARAGRAPH_STYLE");
builder.addTextBody("content", "['sample-title-1']");
builder.addTextBody("button_text", "Get Started");
// builder.addPart("cover_photo", cbFile);
// builder.addBinaryBody("cover_photo", file);
// builder.addBinaryBody("cover_photo", file, ContentType.create(MimeTypeUtils.IMAGE_PNG_VALUE),IMAGE_PATH);
// builder.addBinaryBody("cover_photo", new FileInputStream(file));
httppost.setEntity(builder.build());
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpClient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity));
}
回复:
executing request POST https://graph.facebook.com/167067040143315/leadgen_context_cards HTTP/1.1
HTTP/1.1 500 Internal Server Error
{"error":{"message":"An unknown error has occurred.","type":"OAuthException","code":1,"fbtrace_id":"CHG1SYDq9zn"}}
更新 2
使用以下代码,我可以创建上下文卡片。但是封面照片不见了。
URIBuilder uriBuilder = new URIBuilder(
GRAPH_FACEBOOK_LEADGEN_CONTEXT_CARDS);
uriBuilder.setParameter("access_token", ACCESS_TOKEN);
uriBuilder.setParameter("title", "sample-title-1");
uriBuilder.setParameter("style", "PARAGRAPH_STYLE");
uriBuilder.setParameter("content", "['sample-title-1']");
uriBuilder.setParameter("button_text", "Get Started");
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httppost = new HttpPost(uriBuilder.build());
File file = new File(IMAGE_PATH);
ContentBody cbFile = new FileBody(file,
ContentType.create(MimeTypeUtils.IMAGE_PNG_VALUE));
byte[] bytes = FileUtils.readFileToByteArray(file);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addPart("cover_photo", cbFile);
// builder.addBinaryBody("cover_photo", file);
// builder.addBinaryBody("cover_photo", file,
// ContentType.create(MimeTypeUtils.IMAGE_PNG_VALUE),IMAGE_PATH);
// builder.addBinaryBody("cover_photo", new FileInputStream(file));
// builder.addBinaryBody("cover_photo", bytes,
// ContentType.create(MimeTypeUtils.IMAGE_PNG_VALUE),IMAGE_PATH);
httppost.setEntity(builder.build());
httppost.addHeader(new BasicHeader("Content-Type",
ContentType.MULTIPART_FORM_DATA.getMimeType()));
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpClient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity));
}
根据我在 https://business.facebook.com 的 UI 中的观察。它的第一个上传图片并在 cover_photo_id
.
中传递 id
已将未发布的照片上传到 page/photos
并在 context_card
的 cover_photo_id
中传递了生成的 ID。并且有效。
我正在关注 https://developers.facebook.com/docs/marketing-api/guides/lead-ads/create/v2.8 以创建线索广告的背景卡片。文档说它将接受 cover_photo 字段。 但是,如果我们尝试使用以下参数
从 Graph API Explorer 创建上下文https://developers.facebook.com/tools/explorer/xxxxxx?method=POST&path=<PAGE_ID>%2Fleadgen_context_cards&version=v2.8&title=sample-title-1&style=PARAGRAPH_STYLE&content=[%22sample%20content%201%22]&button_text=Get%20Started&cover_photo=http://xxxxx.s3.amazonaws.com/sample/sampleimage.png
显示以下内容
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1,
"fbtrace_id": "xxxxxx"
}
}
如果我们点击 fgtrace_id 它会显示以下内容
{
"error": {
"message": "(#803) Some of the aliases you requested do not exist: xxxxx",
"type": "OAuthException",
"code": 803,
"fbtrace_id": "yyyyyy"
}
}
如果我们删除 cover_photo
参数,我们就能够创建上下文卡片。
谢谢。
更新 1
我试过上传实际的图像文件。仍然面临同样的问题。以下是代码和响应。
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httppost = new HttpPost(GRAPH_FACEBOOK_LEADGEN_CONTEXT_CARDS);
File file = new File(IMAGE_PATH);
ContentBody cbFile = new FileBody(file, ContentType.create(MimeTypeUtils.IMAGE_PNG_VALUE));
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("access_token", ACCESS_TOKEN);
builder.addTextBody("title", "sample-title-1");
builder.addTextBody("style", "PARAGRAPH_STYLE");
builder.addTextBody("content", "['sample-title-1']");
builder.addTextBody("button_text", "Get Started");
// builder.addPart("cover_photo", cbFile);
// builder.addBinaryBody("cover_photo", file);
// builder.addBinaryBody("cover_photo", file, ContentType.create(MimeTypeUtils.IMAGE_PNG_VALUE),IMAGE_PATH);
// builder.addBinaryBody("cover_photo", new FileInputStream(file));
httppost.setEntity(builder.build());
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpClient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity));
}
回复:
executing request POST https://graph.facebook.com/167067040143315/leadgen_context_cards HTTP/1.1
HTTP/1.1 500 Internal Server Error
{"error":{"message":"An unknown error has occurred.","type":"OAuthException","code":1,"fbtrace_id":"CHG1SYDq9zn"}}
更新 2
使用以下代码,我可以创建上下文卡片。但是封面照片不见了。
URIBuilder uriBuilder = new URIBuilder(
GRAPH_FACEBOOK_LEADGEN_CONTEXT_CARDS);
uriBuilder.setParameter("access_token", ACCESS_TOKEN);
uriBuilder.setParameter("title", "sample-title-1");
uriBuilder.setParameter("style", "PARAGRAPH_STYLE");
uriBuilder.setParameter("content", "['sample-title-1']");
uriBuilder.setParameter("button_text", "Get Started");
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httppost = new HttpPost(uriBuilder.build());
File file = new File(IMAGE_PATH);
ContentBody cbFile = new FileBody(file,
ContentType.create(MimeTypeUtils.IMAGE_PNG_VALUE));
byte[] bytes = FileUtils.readFileToByteArray(file);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addPart("cover_photo", cbFile);
// builder.addBinaryBody("cover_photo", file);
// builder.addBinaryBody("cover_photo", file,
// ContentType.create(MimeTypeUtils.IMAGE_PNG_VALUE),IMAGE_PATH);
// builder.addBinaryBody("cover_photo", new FileInputStream(file));
// builder.addBinaryBody("cover_photo", bytes,
// ContentType.create(MimeTypeUtils.IMAGE_PNG_VALUE),IMAGE_PATH);
httppost.setEntity(builder.build());
httppost.addHeader(new BasicHeader("Content-Type",
ContentType.MULTIPART_FORM_DATA.getMimeType()));
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpClient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity));
}
根据我在 https://business.facebook.com 的 UI 中的观察。它的第一个上传图片并在 cover_photo_id
.
已将未发布的照片上传到 page/photos
并在 context_card
的 cover_photo_id
中传递了生成的 ID。并且有效。