Post photos to an album using a batch request and curl - facebook

I'm trying to post a number of photos to an already created album using cURL with the following command:
curl -F 'access_token=<>' \
-F 'batch=[ \
{"method":"POST","relative_url":"/album_id/photos","url":"<photo_url>"}, \
{"method":"POST","relative_url":"/album_id/photos","url":"<photo_url>"}]' \
https://graph.facebook.com
The error I'm getting is (#324) Requires upload file. Is it even possible to post photos in a batch request to an album and if so what is the correct way to do it with cURL? Thanks!
Edit: the correct command thanks to CBroe is:
curl -F 'access_token=<>' \
-F 'batch=[ \
{"method":"POST","relative_url":"/album_id/photos","body":"url=<photo_url>"}, \
{"method":"POST","relative_url":"/album_id/photos","body":"url=<photo_url>"}]' \
https://graph.facebook.com

Related

How to send HTTP request multipart/form-data Content-Type on Apex Salesforce

I need to recreate this curl post using Apex and I can't find a way to do it.
Seems like Salesforce doesn't support this kind of Content-Type.
curl:
curl -i -X POST \
-H "Content-Type:multipart/form-data" \
-F "message=Images Test" \
-F "login=LOGIN" \
-F "password=PASSWORD" \
-F "to=9999999999" \
-F "image=#\"./20190914_132720.jpg\";type=image/jpeg;filename=\"20190914_132720.jpg\"
Anyone has an example of this on Apex?
Thank you

Getting an INVALID_REQUEST Uber API

In this call to Uber API:
curl -F 'client_secret=<CLIENT_SECRET>' \
-F 'client_id=<CLIENT_ID>' \
-F 'grant_type=authorization_code' \
-F 'redirect_uri=<REDIRECT_URI>' \
-F 'scope=profile' \
-F 'code=<AUTHORIZATION_CODE>' \
https://login.uber.com/oauth/v2/token
from: https://developer.uber.com/docs/riders/references/api/v2/token-post
It was working before, but now I am getting this error:
{
"error": "invalid_request"
}
Where can I find more details about it?
At least know which of the parameters is wrong or invalid?

watson visual recognition error 400: cannot execute learning task: no classifier name given

I was about to create a new classifier and train the visual recognition with pictures, but I got this error code which is stated in title when I curl following command
curl -u "0xxxxxxxxxxx":"vxxxxxxxxxxxxxx" \
-X POST \
-F "positive_examples=#bottle-positive.zip" \
-F "negative_examples=#bottle-negative.zip" \
-F "name=plasticbottle" \
-k "https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classifiers?version=2015-12-02"
To set the classifiers you want to use you have to send a JSON containing something like:
{"classifier_ids": ["ClassifierName"]}
So your curl should be something like:
curl -u "username":"pwd" \
-X POST \
-F "images_file=#imagefilename.jpg" \
-F "classifier_ids={\"classifier_ids\":[\"ClassifierName\"]}"
"https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classify?version=2015-12-02"
I'm not sure what was the problem using V2 api, but now, using V3 API your CURL should look like this example
curl -X POST
-F "apple_positive_examples=#apples1.zip"
-F "banana_positive_examples=#yellow.zip"
-F "orange_positive_example=#pos_ex.zip"
-F "negative_examples=#vegetables.zip"
-F "name=fruit"
"https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers?api_key={api-key}&version=2016-05-20"
So your CURL for bottle should be like
curl -X POST
-F "bottle_positive_examples=#bottle-positive.zip"
-F "negative_examples=#bottle-negative.zip"
-F "name=plasticbottle"
"https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers?api_key={api-key}&version=2016-05-20"
Note that you now should use an api_key to authenticate and no longer a user/pass
This is documented in the v3 doc:
https://www.ibm.com/watson/developercloud/visual-recognition/api/v3/#create_a_classifier

How to post an image on an user's wall directly from disk using the facebook graph api?

On the Facebook Graph API Post documentation the only way of posting images to a wall (user's or page's) is by providing the picture field on the request.
So I could use that and upload the image from my hard-disk to a server and use that url. Like this:
curl --form picture=http://userserve-ak.last.fm/serve/174s/66037848/Foals+png.png --form access_token=AAADChj --form message=msg1 https://graph.facebook.com/242001885843121/feed
But when I do that the type field of the post gets set as "status" and not as "photo".
I tried some different things like using the same request parameters used for uploading an image to an album with no success:
curl --form picture=#/tmp/fb_gallery.png --form access_token=AAADChj --form message=msg2 https://graph.facebook.com/242001885843121/feed
curl --form source=#/tmp/fb_gallery.png --form access_token=AAADChj --form message=msg2 https://graph.facebook.com/242001885843121/feed
I tried to set the type field to "photo" with no luck also.
Try out with this one it can upload 2 photos at a time
curl
–F 'access_token=…' \
-F 'batch=[{"method":"POST", \
"relative_url":"me/photos", \
"body":"message=My cat photo" \
"attached_files":"file1" \
},
{"method":"POST", \
"relative_url":"me/photos", \
"body":"message=My dog photo" \
"attached_files":"file2" \
},
]'
-F 'file1=#cat.gif' \
-F 'file2=#dog.jpg' \
https://graph.facebook.com

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