I try using PHP to get an access token in GoToWebinar API, from this documentation https://developer.goto.com/guides/HowTos/03_HOW_accessToken/
here my php script
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.getgo.com/oauth/v2/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
'Authorization: Basic MWM4ODE2MmItMGZkZS00YTM4LWI0NGMtMWMzOGFhMDY5YmI4OktQSDg2d1hnVUM5a0FqbithMVBsOGc9PQ==',
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
),
CURLOPT_POSTFIELDS =>"redirect_uri=http://indotourismevents.com/webinar&grant_type=authorization_code&code=eyJraWQiOiJvYXV0aHYyLmxtaS5jb20uMDIxOSIsImFsZyI6IlJTNTEyIn0.eyJscyI6IjczYjkyNzhmLTBmNjMtNDE3NC1iYTljLWE3ZTIyYzIwMDhmNyIsInVyaSI6Imh0dHA6Ly9pbmRvdG91cmlzbWV2ZW50cy5jb20vd2ViaW5hci8iLCJzYyI6ImNvbGxhYjogaWRlbnRpdHk6c2NpbS5tZSBpZGVudGl0eToiLCJhdWQiOiIxYzg4MTYyYi0wZmRlLTRhMzgtYjQ0Yy0xYzM4YWEwNjliYjgiLCJzdWIiOiIzODc4MTIxOTUzODYzNTgxMTkwIiwianRpIjoiOTgyYTYyMWQtYTFhYi00NTE3LWFlYTgtNDFlYmY3OWE0NzFlIiwiZXhwIjoxNTk0NzQxOTUxLCJpYXQiOjE1OTQ3NDEzNTEsInR5cCI6ImMifQ.Cy6TR18iKmCtotZnnPvMUS9QMh4EFBP6FMcqBOWN9LtricreNg1qnA45UJB0cQALB1d5h9zgc-nDkU4GtTNr8ZnDSI26On3YqFJBICptmfrHhI7ZZIwH-p8YilKirHua1shEPVpradyAj_epjfmejd35QbCXD8aTz3uq-ocRGZFvz0WZfAA7wWryMBnkvTm5BM4fTx99Q4AGfT27QFomaR4hGsLy6uUM4N3rcqP7VNM21XeuIZ-5U1zd2Ew0-gnWoNo8lOF1hJeihZ_xyMlY9AgN7HAwW55JmUkFSsNVHdLznYebzXuDJZXGYnXxQwIyVym3tmx88JRUcI0bMzJ5-w",
));
$response = curl_exec($curl);
$err = curl_error($curl);
from the documentation, curl must give some header and form body
curl -X POST "https://api.getgo.com/oauth/v2/token" \
-H "Authorization: Basic YTIwfAKeNGYtODY4YS00MzM5LTkzNGYtNGRhMmQ3ODhkMGFhOjNuYU8xMElBMmFnY3ZHKzlJOVRHRVE9PQ==" \
-H "Accept:application/json" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "redirect_uri=https://example.com&grant_type=authorization_code&code=iS0vynEEvRFA9i6kZ8gvNDnnOGE..."
and i give all required header&form body, but still return an error like this
{"error":"invalid_request","error_description":"Required parameter(s) missing or wrong."}
how to PHP get access token from GoToWebinar API?
I experienced this problem when I logged in with the same user account to G2Webinar as my developer user (the oauth client's user was the same as the user webinar user)
Try to register another account.
Related
Am trying to add/upload files to monday.com api via curl in php but the code throws error {"error_message":"Internal server error","status_code":500}
Monday Docs
here is the API Curl request
curl --location --request POST 'https://api.monday.com/v2/file' \
--header 'Authorization: YourSuperSecretAPIKey' \
--form 'query="mutation add_file($file: File!, $item_id: Int!, $column_id: String!) {add_file_to_column (item_id: $item_id, column_id: $column_id, file: $file) {id}}"' \
--form 'variables="{\"item_id\":1104589438, \"column_id\": \"files\"}"' \
--form 'map="{\"image\":\"variables.file\"}"' \
--form 'image=#"/Users/alexsavchuk/Downloads/300px-All_Right_Then,_Keep_Your_Secrets.jpg"'
Arguments Description of the API Variable
item_id !Int The item ID where the file will be added.
column_id !String The column where the file will be added.
file !File The file to upload.
Here is my coding efforts
$token = 'Token goes here';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.monday.com/v2/file',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('query' => 'mutation ($file: File!) { add_file_to_column(file: $file, item_id: 279111, column_id: "files") { id } }','variables[file]'=> new CURLFILE('https://cdn.pixabay.com/photo/2015/05/26/12/30/baby-784608_960_720.jpg')),
CURLOPT_HTTPHEADER => array('Authorization: ' . $token)));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
I am using PHP curl to do basic Auth that return a jwt token.
When I Request the token in shell using curl i get a token of length 381 .However when I do the request in my php code i only get a token of length 326 which is not complete which lead to other problems in my other php requests .
how can i make my php code give me the full length of my token that is 381 in my response and not just 326?
Update my cURL shell code is :
curl --location --request POST 'https://xxxx/xxxx/auth/login' \
--header 'Authorization: Basic XXXXX'
my curl php code :
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://xxxxx/xxxxx/auth/login",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array( "Authorization: Basic xxxxxxx" ),
) );
$response = curl_exec($curl);
curl_close($curl); echo $response;
Thanks
I need to request an api with curl in PHP.
First of all I need to get a token access, and to get it I need to request to this url (with my "client_id") : https://testexellia.bitrix24.fr/oauth/authorize/?response_type=code&client_id=local.5d3c9f79b65439.23207420&redirect_uri=app_URL
It should answer me a new url with the token inside.
It works very well when I request with Chrome, but with curl I get this answer -> https://www.bitrix24.net/oauth/authorize/?user_lang=fr&client_id=b24.5d399107d0f2b9.16511658&redirect_uri=https%3A%2F%2Ftestexellia.bitrix24.fr%2Foauth%2Fauthorize%2F%3Fauth_service_id%3DBitrix24Net%26oauth_proxy_params%3DcmVkaXJlY3RfdXJpPWFwcF9VUkwmY2xpZW50X2lkPWxvY2FsLjVkM2M5Zjc5YjY1NDM5LjIzMjA3NDIwJnJlc3BvbnNlX3R5cGU9Y29kZQ%253D%253D%26sessid%3Db6ded2712b7e66e4b34f05411eb2f4f1&scope=auth,profile&response_type=code&mode=page&state=site_id%3Ds1%26backurl%3D%252Foauth%252Fauthorize%252F%253Fcheck_key%253D7d6109a54034f59c406798d6a9667a9c%2526response_type%253Dcode%2526client_id%253Dlocal.5d3c9f79b65439.23207420%2526redirect_uri%253Dapp_URL%26mode%3Dpage
So the login page.
I know where is the problem, I'm already logged with Chrome (probably with cookies I guess) to the website, and obviously the curl request not.
I guess I need to add some headers informations to my request, like a password and login, but I'm logged to this website with my Google Account.
So is there a way to add Google informations in the curl's header ? I can't find how.
Here is the doc of the API, in case you need.
Edit : Here is the code.
$curl = curl_init();
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://testexellia.bitrix24.fr/oauth/authorize/?response_type=code&client_id=local.5d3c9f79b65439.23207420&redirect_uri=app_URL&sessid=b6ded2712b7e66e4b34f05411eb2f4f1",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Accept: */*",
"Authorization: Bearer 08493f5d003eabc0003e9b9e00000001f0f103a29e30c5356d8e8142404add6515e135",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Host: testexellia.bitrix24.fr",
"Postman-Token: 6de6ba41-b9fc-4541-98b0-c2f9d9b1ea7f,b36cd02a-87f8-4fb1-821c-54602a300bc5",
"User-Agent: PostmanRuntime/7.13.0",
"accept-encoding: gzip, deflate",
"cache-control: no-cache",
"cookie: PHPSESSID=fOJKQhrXBNuNmrmIOXXg0YDlIeckdVfm; qmb=.; BITRIX_SM_SALE_UID=0"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
$content = curl_exec($curl);
$redirectedUrl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
curl_close($curl);
echo $redirectedUrl;
Thank you very much.
Benjamin.
I am working on a Hootsuite script that needs to upload a file using cURL PUT request. On Hootsuite site, I found below example code but I am being able to convert below code in PHP script :
curl -X PUT -H 'Content-Type: video/mp4' \
-H "Content-Length: 8036821" \
-T "/Users/kenh/Downloads/amazing_race.mp4" \
"https://hootsuite-video.s3.amazonaws.com/production/3563111_6923ef29-d2bd-4b2a-a6d2-11295411c988.mp4?AWSAccessKeyId=AKIAIHSDDN2I7V2FDJGA&Expires=1465846288&Signature=3xLFijSn02YIx6AOOjmri5Djkko%3D"
I tried below code but it is still not working :
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://hootsuite-video.s3.amazonaws.com/production/3563111_6923ef29-d2bd-4b2a-a6d2-11295411c988.mp4?AWSAccessKeyId=AKIAIHSDDN2I7V2FDJGA&Expires=1465846288&Signature=3xLFijSn02YIx6AOOjmri5Djkko%3D",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => array('file' => '#' . realpath('/Users/kenh/Downloads/amazing_race.mp4')),
CURLOPT_HTTPHEADER => array(
'Content-Type: video/mp4',
'Content-Length: 8036821'
)
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
So can anybody help me out by telling how to convert above code in PHP ?
I'll be thankful.
Try appending http_build_query on the CURLOPT_POSTFIELDS option, like below :
CURLOPT_POSTFIELDS => http_build_query( array( 'file' => '#' . realpath( '/Users/kenh/Downloads/amazing_race.mp4' ) ) ),
From what I know, the http_build_query is required on the post fields when using PUT method.
I'm trying to curl to PayPal to create payment URL, and I've bought a cert meet PayPal requirement.
When I first call the curl it return error
NSS: client certificate not found (nickname not specified)
But when I try to reload the page within few second the curl return success.
Is there any way for me to set the cert in curl?
I've read the other ansewer but some links were dead and the answer does not work for me.
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.paypal.com/v1/payments/payment",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{"intent":"sale","redirect_urls":{"return_url":"'.$return.'","cancel_url":"'.$cancel.'"},"payer":{"payment_method":"paypal"},"transactions":[{"amount":{"total":"'.$amount.'","currency":"HKD"}}]}',
CURLOPT_HTTPHEADER => array(
"authorization: Bearer $token",
"cache-control: no-cache",
"content-type: application/json",
"postman-token: 7ca12352-aa45-2c4e-d87d-fdd09795121d"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
// If I added this refresh code it works!?
/*
if ($err) {
header("Refresh:0");
}
*/