I'm struggling to find a method to retrieve attachments from a message via the Graph API.
When I request the message (m_mid.xxxxxx/attachments), I get the response:
"data": [
{
"id": "105446924xxxxxx",
"mime_type": "application/pdf",
"name": "some.pdf",
"size": 89628
}
]
Any way to get the attachment link or the file itself?
The documentation only lists four fields that you can use as query parameters to filter the results, and these are the same as the response to your request.
However, if you remove the fields parameter from the request, you'll also get an image_data object which includes URLs.
For example:
https://graph.facebook.com/v5.0/{message_id}/attachments?access_token={page_access_token}
Related
I have created different API queries on searching hashtags and searching recent media with that. This all works fine. but when I grab the ID from media objects from the recent_media query and try to query them separately since then I'm able to query more data. It won't work.
https://graph.facebook.com/v7.0/ig_hashtag_search?access_token={token}&user_id={user_id}&q=hashtag_name
This returns
"data": [
{
"id": "17843780662045901"
}
]
Then I query
https://graph.facebook.com/v7.0/17843780662045901/recent_media?access_token={token}&user_id={user_id}&fields=id,media_url
with result
"data": [
{
"id": "17939405797365335"
},
{
"id": "17868693508835640"
},
and then I try to access media with
"get graph.facebook.com/{graph-api-version}/ig_media_id?fields=id,username" endpoint
I get
{'error':
{'message': "Unsupported get request. Object with ID '17930129249499764' does not
exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at
https://developers.facebook.com/docs/graph-api", 'type': 'GraphMethodException',
'code': 100, 'error_subcode': 33, 'fbtrace_id': 'A0mF0lmOv0VzfO-dN6NTTFA'}}
Following permissions granted at standard access level to my facebook ap:
'instagram_basic',
'pages_show_list',
'pages_read_engagement'
What is the source of problem?
And Is there an alternative wethod to get owner username of an media from media id or media_url using graph api?
Thanks in advance,
We have a site where our agents enter in some data, and then that data is sent to a client, via a SendGrid dynamic template.
The email content includes a lot of calculations based on the data entered, so we want our agents to have the ability to preview the email and verify the content first before sending it to the client.
Is there a way to use the SendGrid API to send a request with our json object, but instead of sending the email to the client, receive the generated email body so that we can display it to the agent and let them review it first?
Answered my own question. API v3 has GET methods for Dynamic Transactional Templates and Template Versions.
API Call:
/templates/{template_id}/versions/{version_id}
using sendgrid-ruby:
sg = SendGrid::API.new(api_key: sendgrid_api_key)
sg.client.templates._(template_id).versions._(template_version_id).get
(Note: the template_version_id is the ID and not the Name of the template version)
The response body then includes a field called html_content which is the full rendered HTML of a dynamic template version with any handlebar templating.
You can make API call via postman as:
https://api.sendgrid.com/v3/templates/d-d44fdfsdfdsfd342342343
with Bearer token along with Sendgrid API key like:
Bearer SG.Fvsdfsdjfksdfsdfjsdkjfsdfksjdfsdfksjdfkjsdkfjsdf
The response is:
{
"id": "d-d55d081558a641b48a8a1145b4549fbe",
"name": "Bt_Payment_Reminder (Active)",
"generation": "dynamic",
"updated_at": "2021-12-21 07:35:12",
"versions": [
{
"id": "a95c3652-e49f-4608-a9dd-5aa4831c2dc3",
"user_id": 11702857,
"template_id": "d-d55d081558a641b48a8a1145b4549fbe",
"active": 1,
"name": "Bt_Payment_Reminder_Updated",
"html_content": "Hello {{firstName}}",
"plain_content": "Hello {{firstName}}",
"generate_plain_content": true,
"subject": "{{subject}}",
"updated_at": "2021-12-21 07:37:48",
"editor": "code",
"test_data": "{\n \"firstName\":\"Virendra\"}",
"thumbnail_url": "sdasdasdasdasdasdsd"
}
]
}
My goal is to create a number of ads using Facebook's Batch API : https://developers.facebook.com/docs/marketing-api/asyncrequests/v2.9
I am sending a POST request at this URL:
https://graph.facebook.com/v2.9/act_158365238/ads
I am sending 2 parameters as per the documentation:
1- access_token
2- batch
The JSON in the batch parameter looks like :
{
"method": "POST",
"relative_url": "v2.9\/act_158365238\/ads",
"attached_files": "test1",
"body": "creative={\"title\":\"Test title 1\",\"body\":\"Test body 1\",\"object_url\":\"https:\/\/apps.facebook.com\/testapp\/\", \"image_file\":\"test1.jpg\"}&targeting={\"countries\":[\"US\"]}&name=test1"
}
The Problem
When I send this request with POSTman or my PHP code, it throws the following error
{
"error": {
"message": "(#100) The parameter creative is required",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "Gj2sG7N8l1f"
}
}
However when I send the exact same request via Facebook's Graph API tool, it successfully creates the ads.
According to the API Documentation provided to create creatives you should be posting to the URL "v2.9/act_187687683/adcreatives"... The fragment of the batch that you are showing is used to create an Ad.
If, as you say, your intention is to create an AdCreative then you should be using something like the above, which differs in the body from what you are using:
{
"method": "POST",
"name": "create_creative",
"relative_url": "v2.9/act_187687683/adcreatives",
"attached_files": "test1",
"body": "title=Test title&body=Test body&link_url=http://www.test12345.com&image_file=test1.jpg"
}
In the other hand, if what you are creating is an add, then you should consider referencing the AdCreative by its ID as is done in the examples, hence in the case of a creative added in the same batch you could use the relative reference to the name:
creative={\"creative_id\":\"{result=create_creative:$.id}\"}
or if it is a creative already created you can reference it by the creative_id:
creative={\"creative_id\":\"123456\"}
I think the message is a red herring -- it's not seeing your body's creative field because the OAuth isn't properly set in your POSTman requests, so it isn't parsing the body or seeing the creative field.
If you don't know how to set OAuth in POSTman, here's a good tutorial:
https://docs.brightcove.com/en/video-cloud/concepts/postman/postman.html
Let's say I know the group I'm interested in has this URL: https://www.facebook.com/groups/framerjs/.
I've been looking for a way to map an URL like this (without any other source of information) to a specific group ID, using the Graph API, but there seems no way to do that.
I've experimented with the following:
Accessing /me/groups:
This endpoint gives out the groups I've subscribed to (within which the group I'm looking for is included), but there's no information in the response that lets me map framerjs to an ID, since the response will only contain the full (formatted) group name, such as Framer JS.
Using the group alias directly, e.g. /framerjs/feed:
This returns an error like (#803) Some of the aliases you requested do not exist: framerjs, supposedly because the API only allows using aliases for users and/or pages, and not groups.
You can use the Search API:
/search?q=framerjs&type=group
Response:
{
"data": [
{
"name": "Framer JS",
"id": "385961098197634"
}
],
"paging": {
"next": "https://graph.facebook.com/v2.2/search?type=group&q=framerjs&icon_size=16&limit=5000&offset=5000&__after_id=enc_AewsQta1G58IkwuUNLJ8vZb35qrc0BS89MpO1ZiAVCRiwYjzWE_GkHRwxk6I1E5Sj2UprSuDxghIB4EJGEF8GxD7"
}
}
is there a possibility to get more informations to a specific url e.g. preview image, title and short description through the open graph? If you do something like this, you only get the "shares" //graph.facebook.com/http://www.google.de
It's a bit confusing, when I get the ID via FQL through the object_url Table I get a different ID to the ID I get from the Debugger.
Getting the ID:
//graph.facebook.com/fql?q=SELECT%20url,id,type,site%20FROM%20object_url%20WHERE%20url%20=%20%22http://google.de%22
Result: "id": 6319338796</pre>
Trying to get the Data with that ID failed (acces token needed)
//graph.facebook.com/6319338796/
"message": "An access token is required to request this resource."
Get the ID with the Debugger:
//developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fgoogle.de
Getting the Result from ID 438699604740 (no problem):
//graph.facebook.com/438699604740
{
"url": "http://www.google.de/",
"type": "website",
"title": "Google",
"image": [{"url": "http://www.google.de/images/google_favicon_128.png"}
],
"updated_time": "2012-12-19T15:26:32+0000",
"id": "438699604740"
}
I am just wondering, why there are two different object IDs for the same URL and why do I need for the one an acces_token and not for the other?
The question is, how to get the right Data and the right ID throug the API? Or are there any restrictions to get these Data from a URL?
Thanks for help!