I am following https://developers.facebook.com/docs/marketing-api/guides/lead-ads/create/v2.8 to create context card for lead ad. document says it will accept cover_photo field. But if we try to create context from Graph API Explorer with following params
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
its showing following
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1,
"fbtrace_id": "xxxxxx"
}
}
And if we click on fgtrace_id it showing following
{
"error": {
"message": "(#803) Some of the aliases you requested do not exist: xxxxx",
"type": "OAuthException",
"code": 803,
"fbtrace_id": "yyyyyy"
}
}
If we remove cover_photo
param we are able to create context cards.
Thanks.
I have tried to upload the actual image file. Still facing same issue. Following is code and response.
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));
}
Response:
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"}}
With following code I am able to create context card. but cover photo is missing.
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));
}
As per my observation in https://business.facebook.com's UI. Its first uploading image and passing id in cover_photo_id
.
Uploaded unpublished photo to page/photos
and passed generated Id in context_card
's cover_photo_id
. and its worked.