How to send tweets with curl? - php

I need help because in my team we are using an old version of php and its impossible to use any bundle.
I'm trying to make the request with curl but Im having a lot of problems with authentication.
Could anyone tell me how to make a simple curl request to send a tweet using the twitter api?
Thanks a lot!!

curl -X POST 'https://api.twitter.com/2/tweets/search/stream/rules' \
-H "Content-type: application/json" \
-H "Authorization: Bearer $APP_ACCESS_TOKEN" -d \
'{
"add": [
{"value": "cat has:images", "tag": "cats with images"}
]
}'
it's just an example - but it's nicely described in the documentation

Related

Microsoft-Cognitive Text Translation API

AZURE - The official documentation and examples for PHP is not working, help?
I am using the code at this link:
https://github.com/courtney7/HTTP-Code-Samples/blob/37a4431f75397e1ccc6ee3f62ef14b3909a2dc85/PHP/PHPAzureToken.php
Always test and debug APIs using curl (i.e. take a curl first approach). Here's an example that works on my Windows 10 system. Here's the curl that gets a token.
curl -k --data "" "https://api.cognitive.microsoft.com/sts/v1.0/issueToken" -H "Ocp-Apim-Subscription-Key:<your Ocp-Apim-Subscription-Key>"
Example to get token and call text translate.
curl -k --data "" "https://api.cognitive.microsoft.com/sts/v1.0/issueToken" -H "Ocp-Apim-Subscription-Key:<your Ocp-Apim-Subscription-Key>" > Bearer.txt
set /p Bearer= < Bearer.txt
curl -H "Authorization: Bearer %Bearer%" "https://api.microsofttranslator.com/v2/Http.svc/Translate?Text=Hello+world.&From=en&To=es"
Make sure you are calling the correct endpoint "https://api.cognitive.microsoft.com/sts/v1.0/issueToken"

using curl in php with bearer authorization

im want to use curl with php to send push-messages to an ionic-app. this is my command im using on the commandline:
curl -X POST -H "Authorization: Bearer XXXXXX.AUTH.XXXXXXX" -H "Content-Type: application/json" -d '{
"tokens": ["XXXX.DEVICE_TOKEN.XXXX"],
"profile": "XXXX.PROFILE.XXXXX",
"notification": {
"message": "This is a test-message",
"title": "This is a Test Title"
}
}' "https://api.ionic.io/push/notifications"
how can i execute this command in php? i found some examples, but none of them works.

cURL command to POST with data embedded in request

I am writing a simple shell script using which I will create a request in JIRA when conditions are met using curl. Following is the JIRA way of executing it, which needs me to send send the request as a command and parameters using a data file:
Request:
curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/
Data:
{
"fields": {
"project":
{
"key": "TEST"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}}}
So I don't want to use a separate data file as shown above. Rather I would like to using a single curl Request which has the data embedded in the request. Something like:
curl -D- -u fred:fred -X POST --"**PASS ALL MY DATA HERE**" -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/
I know it will make things cluttered, but thats the way i want it. Can you please suggest if the above is feasible.
Can you do it with a here document?
curl -D- -u fred:fred -X POST -d - -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/ <<EOF
{
"fields": {
"project":
{
"key": "TEST"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}}}
EOF

How to create the get method for the call

I am studying and implementing an api and while following the examples,
Here is the example 1 :
curl -X POST \
-H "Content-Type: application/json" \
-H "QuickBlox-REST-API-Version: 0.1.0" \
-d '{"application_id": "2", "auth_key": "DtF9cZPqTF8Wy9Q", "timestamp": "1333630580", "nonce": "1340569516", "signature": "13293a5bd2026b957ebbb36c89d9649aae9e5503", "user": {"login": "injoit", "password": "injoit"}}' \
https://api.quickblox.com/session.json
For the above example i consructed my get method as
https://api.quickblox.com/session.json?token=re8d22c6e617133ffeadd761193a6c57d87bfb1a0f&application_id=23995&auth_key=CbRasu4Wftu25Qw&nonce=8796&timestamp=1434446627&signature=667ee2b448a5d3dd57d112afef3f84dd6c67e165
and it is working good.
But for the below example
curl -X POST \
-H "QuickBlox-REST-API-Version: 0.1.0" \
-H "QB-Token: 17f6a337b0656c9c7e983f9705d79562fc694c0e" \
-H "Content-Type: application/json" \
-d '{"push_token": {"environment": "production", "client_identification_sequence": "aa557232bc237245ba67686484efab"},
"device": {" platform": "iOS", "udid": "5f5930e927660e6e7d8ff0548b3c404a4d16c04f"}}' \
http://api.quickblox.com/push_tokens.json
How can i create the get method. As this has two main arrays i am little confused.
Can anyone help in creating how can i use this call ?
It should be something like this:
https://api.quickblox.com/push_tokens.json?push_token[environment]=production&push_token[client_identification_sequence]=aa557232bc237245ba67686484efab&device[platform]=iOS&device[udid]=5f5930e927660e6e7d8ff0548b3c404a4d16c04f

INTERNAL_SERVICE_ERROR when trying to verify payment via paypal REST API

I'm trying to validate a payment made through a partner service. The partner is passing me the payment id and I'm using the REST API to look it up. So far, all attempts to use the payments/payment/<Payment-Id> are throwing an INTERNAL_SERVICE_ERROR. (I'm still using the sandbox and demo user.)
Getting a token seems to be working fine:
curl -v https://api.sandbox.paypal.com/v1/oauth2/token -H "Accept: application/json" -H "Accept-Language: en_US" -u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp" -d "grant_type=client_credentials"
Response:
{"scope":"https://api.paypal.com/v1/developer/.* https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/vault/credit-card/.*","access_token":"A015GzttpnOSOPfcqtfAaq1kdgqow5W.IXSe6TJ9Cpbesr4","token_type":"Bearer","app_id":"APP-8KK24973T6066201W","expires_in":28800}
Taking that token and putting into the payment request:
curl -v -X GET https://api.sandbox.paypal.com/v1/payments/payment/PAY-8UD377151U702286RKOQ3DTQ -H "Content-Type:application/json" -H "Authorization: Bearer A015GzttpnOSOPfcqtfAaq1kdgqow5W.IXSe6TJ9Cpbesr4"
returns the error:
{"name":"INTERNAL_SERVICE_ERROR","message":"An internal service error has occurred","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#INTERNAL_SERVICE_ERROR","debug_id":"ca33c7679121d"}
UPDATE: basically I'm trying to follow the steps outlined here: https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/

Categories