Post to a Facebook user's wall with curl PERL - facebook

I'm storing facebook userid's and access tokens. Can I post to a selected user's wall with this information? The following code is found at Facebook's developer reference.
I'm just not sure how to run it with Perl.
curl -F 'access_token=$accessToken' \
-F 'message=Check out this funny article' \
-F 'link=http://www.example.com/article.html' \
https://graph.facebook.com/$facebookid/feed
or this code:
curl -F 'access_token=$accessToken' \
-F 'photo=http://samples.ogp.me/$appID' \
'https://graph.facebook.com/me/$appNameSpace:$objectType'

Why not use the Facebook::Graph module to do what you need? It's a rich wrapper around the facebook API.

You need to perform a HTTP POST request with these form data, see method post in LWP::UserAgent.

Related

Facebook Marketing API CURL Example for all Ad Website URL's

i'm currently serching for a solution to get all ad links pointing to my Website via the Facebook Marketing API. My current approch is collecting all ads in the Account:
curl -G \
-d "level=ad" \
-d "fields=spend,impressions,ad_id" \
-d "date_preset=yesterday" \
-d "access_token=<token>" \
"https://graph.facebook.com/v2.9/act_<id>/insights"
and than loop over all Ids
curl -G \
-d "fields=id,name,body" \
-d "level=ad" \
-d "access_token=<token>" \
"https://graph.facebook.com/v2.9/<ad-id>"
Sadly if I use the ad-id from the insights I get the Error : "message":"(#100) Tried accessing nonexisting field (link) on node type (Adgroup)". Wy does the Insights return a Adgroup for a ad? Does anybody know a workaround?
All the best
Daniel
There is no field called body in Ads. Your call is failing because FB is telling you that you cannot retrieve a non-existing field. You can look up the available fields for "Ad" object at https://developers.facebook.com/docs/marketing-api/reference/adgroup
Also, I would try using graph.facebook.com/v2.9/act_<id>/ads to get the ad ids instead of insights call. You will get a cleaner JSON response like this:
`
{
"data": [
{
"id": "<ad_id_1>"
},
{
"id": "<ad_id_2>"
},
....
`

How should I do with CURL in Facebook Messenger Platform(Chatbot)?

I'm working on Facebook chatbot, and I found some difficulties while reading Facebook's official Messenger Platform tutorial.
The frustrating part is here:
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"greeting",
"greeting":{
"text":"Timeless apparel for the masses."
}
}' "https://graph.facebook.com/v2.6/me/thread_settings?access_token=PAGE_ACCESS_TOKEN"
I'm using a Node.js and Heroku. How should I use the code above to make it work?
If you're on OSX you can use the terminal to run the command. On windows you could use Git Bash.
Copy & paste your curl command, replace PAGE_ACCESS_TOKEN with your token from your Facebook Developer App and run it by pressing the enter key.
Hope that helps.

Graph API bug - posting links, missing description

When posting a link on a page using the Graph API, the description is missing.
Might be related to this bug http://bugs.developers.facebook.net/show_bug.cgi?id=14782.
Is this going to be fixed? Now I'm posting as feed/ instead, here the description is shown - but then there is no "share" button.
Any known workaround?
I'm not sure why this is, and really it doesn't make much intuitive sense, but I've had success posting to the PAGE_ID/links feed, rather than identifying the page ID independently and then just posting to graph.facebook.com/links
Thus, I'm posting using:
curl -F 'access_token=ACCESS_TOKEN' \
-F 'link=LINK' \
-F 'name=TITLE' \
-F 'description=DESCRIPTION' \
https://graph.facebook.com/PAGE_ID/links
Rather than:
curl -F 'access_token=ACCESS_TOKEN' \
-F 'link=LINK' \
-F 'name=TITLE' \
-F 'description=DESCRIPTION' \
-F 'id=PAGE_ID' \
https://graph.facebook.com/links
In my testing, the former allows proper formatting of each of the elements, while the latter does not. Both surface the share link. I do not know why this is, but it works.
Hope this helps.

Facebook Application: Uploading multiple images in one post to wall

How to upload multiple images in one post via api?
Like here:
http://www.facebook.com/SocialCity?v=wall
I have managed to upload only one image via curl request.
curl
-F "access_token=token_here"
-F "message=message_here"
-F "picture=http://www.example.com/image.jpg"
https://graph.facebook.com/app_id_here/feed
Or it's not possible to post multiple images this way?
Anyone?
Thanks ;)
It's possible by now with the Open Graph however it seems to apply only to user generated fotos:
https://developers.facebook.com/docs/opengraph/usergeneratedphotos/
Multiple photo upload via one Graph API call is not supported. However you can create individual api calls and batch those in one request described here: https://developers.facebook.com/docs/reference/api/batch/
You can now publish multiple images in a single post to your feed or page:
For each photo in the story, upload it unpublished using the {user-id}/photos endpoint with the argument published=false
curl -i -X POST \
-d "url=https%3A%2F%2Fwww.facebook.com%2Fimages%2Ffb_icon_325x325.png" \
-d "caption=test%20photo%20upload" \
-d "published=false" \
-d "access_token=<user_photos_token>" \
"https://graph.facebook.com/v2.6/me/photos"
You'll get an ID for each photo you upload like this:
{
"id": "10153677042736789"
}
Publish a multi-photo story using the {user-id}/feed endpoint and using the ids returned by uploading a photo
curl -i -X POST \
-d "message=Testing%20multi-photo%20post!" \
-d "attached_media%5B0%5D=%7B%22media_fbid%22%3A%221002088839996%22%7D" \
-d "attached_media%5B1%5D=%7B%22media_fbid%22%3A%221002088840149%22%7D" \
-d "access_token=<publish_actions_token>" \
"https://graph.facebook.com/v2.6/me/feed"
Source: Publishing a multi-photo story

How to post a link with a picture to Facebook using the Graph API?

I have tried two different methods.
The first is to specify the link in the /PROFILE_ID/feed link argument (as described under "publishing" here). The problem is that if I specify anything other than my application URL i get an error saying the URL is invalid.
The second is to use the /PROFILE_ID/links method and specifying a picture URL. The problem is that when it posts it only shows the message and the URL. I've specified values for picture, name and message but none of them show.
How can I Post a link, with a name, message and picture?
Your first approach is the correct one. Is your url starting with http://? What SDK are you using?
As described on this page, the example suggest it should work.
http://developers.facebook.com/docs/reference/api/post
curl -F 'access_token=...' \
-F 'message=Check out this funny article' \
-F 'link=http://www.example.com/article.html' \
-F 'picture=http://www.example.com/article-thumbnail.jpg' \
-F 'name=Article Title' \
-F 'caption=Caption for the link' \
-F 'description=Longer description of the link' \
-F 'actions={"name": "View on Zombo", "link": "http://www.zombo.com"}' \
-F 'privacy={"value": "ALL_FRIENDS"}' \
-F 'targeting= {"countries":"US","regions":"6,53","locales":"6"}' \
https://graph.facebook.com/me/feed
I ended up solving this problem by using the /PROFILE_ID/feed method and then disabling Stream post URL security in my application security settings. Hope this helps someone!