How should I do with CURL in Facebook Messenger Platform(Chatbot)? - 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.

Related

Downloading an artifact from actions on someone else's repository

This problem seems really simple. I'm trying to download a pre-built binary for a program from somebody's github repo.
They suggest that I can do this:
"You can also download pre-built binaries from GitHub Actions artifacts."
But it turns out that I have no idea what that means!
The file is not in the actions page (I'm not sure if it should be) and when I try:
curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/nbdd0121/wsld/actions/artifacts/42682371/zip
I receive { "message": "You must have the actions scope to download artifacts.", "documentation_url": "https://docs.github.com/rest/reference/actions#download-an-artifact" }
But this documentation implies that I need to Build an app in order to download a file???
Can this possibly be correct?
What am I missing here?
This works for me:
curl.exe `
--netrc-file C:\Users\Steven\_netrc `
-L `
-o wsldhost.exe.zip `
https://api.github.com/repos/nbdd0121/wsld/actions/artifacts/42682371/zip
Where _netrc looks like this:
default login <USERNAME> password <PERSONAL ACCESS TOKEN>
https://github.com/actions/upload-artifact/issues/89
You can also directly use Basic auth. In curl:
curl -L -u <USERNAME>:<PERSONAL_ACCESS_TOKEN> -o artifact.zip https://api.github.com/repos/nbdd0121/wsld/actions/artifacts/42682371/zip
And the personal access token is generated at: https://github.com/settings/tokens

How to associate a project with a quality profile in Sonarqube

I am using sonar webapi to associate a project with a quality profile but not able to do it. On every run of sonnar-scanner it is associating default quality profile. Below is the code snippet.
Updated the code snippet
curl -k -X POST --insecure -H “X-Auth-Token:XXX” -d "language=py" -d "qualityProfile=test_profile" -d “project=test_1.0” https://sonartest.xxx.com/api/qualityprofiles/add_project
I am not sure what I am doing wrong. I have administrative access and followed the webapi of Version 6.7.3 (build 38370)
Finally got some help from Soanrqube community. I need to remove X-Auth-Token from code. It should be something like this
curl -u ur_token: -X POST -d language=py -d qualityProfile=test_profile -d projectKey=${params.ProjectName} https://sonar-url.com/api/qualityprofiles/add_project

Facebook Messenger bot welcome message: 100 The parameter setting_type is required

I'm trying to set a welcome message for a Facebook Messenger bot using the code provided in the documentation - with my own page ID and page access token
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[{
"message":{
"text":"Hello! This is a Messenger bot!"
}
}]
}' "https://graph.facebook.com/v2.6/<PAGE_ID>/thread_settings?access_token=<PAGE_ACCESS_TOKEN>"
This returns the following:
{"error":{"message":"(#100) The parameter setting_type is required","type":"OAuthException","code":100,"fbtrace_id":"B0DKyn9O2KB"}}
Any ideas on how to solve this? Thanks.
I had the same problem! Some strange copy/paste error with the cURL command from fb...
It didn't work with cURL, but then I used "Advanced REST client" (Chrome plugin) and I was able to set the Welcome Message.
I've tried those exact params with my own page and they worked fine.
Can you try these steps?
Get your page ID and a fresh access token from the Facebook developer console
Make the request from https://developers.facebook.com/tools/explorer to make sure it isn't a problem with cURL
I was having the same issue and the reason was just stupid:
I made copy paste from FB doc and some quotes were wrong. They were ” instead of ".
Open your file in vi or something and search for all quotes so that u can easily understand which are wrong.
I had the same issue, i solved it be calling the URL by postman.check image
There seems to be a problem with windows cmd interpreting the commands. Can you try the same code using Cygwin. It worked well for me. Cheers
this is what works for me
curl --location --request POST 'https://graph.facebook.com/v13.0/your_api_id/messages' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer your_App_Token' \
--data-raw '{
"messaging_product": "whatsapp",
"preview_url": false,
"recipient_type": "individual",
"to": "33732473829",
"type": "text",
"text": {
"body": "Hello,"
}
}'
I had to specify the access token in the header

Post to a Facebook user's wall with curl PERL

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.

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