Automating Zoom API authentication with PHP not working - php

I am trying to automate the sign in process with the Zoom API to allow me to use my website to create meetings but I cannot seem to get the sign in to work in order to allow me to get an authentication code to call the API methods. I am doing this in PHP and I am fairly novice so may be making some fundamental errors.
If I make the 2 calls in the code below via postman and copy the code from postman to my PHP then it works for an hour (My guess is that this is because the cookies have an hour expiry?). Given I thought it was down to cookies I have tried a couple of way to copy the cookies returned in the set-cookie header but this still isn't working. Can someone help me with what I am missing? Apologies if the code is messy...
<?php
$curl = curl_init();
$headers = [];
curl_setopt_array($curl, array(
CURLOPT_URL => "https://zoom.us/oauth/v2/signin",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_HEADERFUNCTION => function($curl, $header) use (&$headers)
{
$len = strlen($header);
$header = explode(':', $header, 2);
if (count($header) < 2) // ignore invalid headers
return $len;
$headers[strtolower(trim($header[0]))][] = trim($header[1]);
return $len;
},
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array('email' => 'some#thing.com','password' => 'somePassword','client_id' => 'someClientID','redirect_uri' => 'https://www.some.thing','response_type' => 'code','scope' => '','state' => ''),
));
$response = curl_exec($curl);
$cookie2 = "Cookie: ";
echo "<br>_____<br>";
print_r($headers["set-cookie"]);
echo "<br>_____<br>";
//echo var_dump(curl_getinfo($curl));
foreach ($headers["set-cookie"] as &$value) {
echo "<br>------------<br>";
echo $value;
$cookies = explode(';', $value);
$cookie2 .= $cookies[0] . "; ";
}
unset($value);
echo "<br>_____<br>";
echo $cookie2;
echo "<br>_____<br>";
echo $response;
$nextUrl = json_decode($response, true)["nextUrl"];
// -------------------------------------------
//$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://zoom.us/oauth/authorize?client_id=clientID&response_type=code&redirect_uri=https://www.some.thing",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
$cookie2
),
));
$response = curl_exec($curl);
curl_close($curl);
$pieces = explode("> ", $response);
$authCode = substr($pieces[1], 0, -3);
echo "auth code: " . $authCode;
// ---------------------------------------------------------------
?>

My Solution for this was to use a refresh token call instead to avoid the need for signing in for every call. Now for each call to the Zoom API I refresh the token and then make the API call, storing the tokens on the server for future use.

Besides refreshing your token for each request, you can generate immortal tokens with your own client secret on the jwt token site. For example, I produced a valid token until 2052 and can request as many requests as I want.
Firstly, you should take your token from Zoom and open jwt.io web site and paste it here. You can change the timezone, exp: expiring time, iat: starting time
Finally, you pass your client_secret key

Related

How to Execute an API in browser using PhP

THE FOLLOWING CODE IS RUNNING SMOOTHLY IN MY LOCALHOST. BUT WHEN I UPLOAD THIS FILE IN WEBSERVER[HOSTINGER], IT IS NOT RUNNING.
$partmsg="https://wapush.in/api/send.php?number=";
$partmsg.=$mobno;
$partmsg.="&type=text&message=Dear Admin User $adminname Your Current Password is ";
$partmsg.=$pwd;
$partmsg.=" - GSFCS&instance_id=63D79C168ACAF&access_token=134ac4a6ec1c01c6825b67ddeba70fa8";
$data = [
'collection' => 'RapidAPI'
];
$curl = curl_init($partmsg);
$response = curl_exec($curl);
echo "<script>alert('Your Password is Send to your Registered Mobile Number.');</script>";
IS THERE ANY OTHER WAY TO EXECUTE THE $URL OTHER THAN RapidAPI that I used.
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://wapush.in/api/send.php?number=91<10_digit_no>&type=text&message=Dear%20Admin%20User%20$adminname%20Your%20Current%20Password%20is&instance_id=<your_instance_id>&access_token=<your_access_token>',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Try this code. I have tested it. its works with the credentials that you shared. Please don't share your credentials as I see it isfrom gun sheel factory. Remove them immediately
Upvote and accept this as a answer

PHP CURL How to GET cookie like POSTMAN?

Hi I'm trying to setup a PHP CURL call using OAuth1 authorization method.
I've tried with POSTMAN 1st, to generate the PHP code. I've completed it with the necessary datas
<?php
$conskey = 'XXXXXXX';
$conssec = 'XXXXXXX';
$nonce = mt_rand();
$timestamp = time();
$url = 'https://some-website/api/project/subproject';
$method = 'POST';
$oauth = new OAuth($conskey, $conssec, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->setNonce($nonce);
$oauth->setTimestamp($timestamp);
$signatureOAuth = $oauth->generateSignature($method, $url);
$curl = curl_init($url);
curl_setopt_array($curl, array(
CURLOPT_URL => $url.'?oauth_consumer_key='.$conskey.
'&oauth_signature_method=HMAC-SHA1&oauth_timestamp='.$timestamp.
'&oauth_nonce='.$nonce.
'&oauth_version=1.0&oauth_signature='.$signatureOAuth,
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 => $jsonDatas,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
// THE COOKIE I WANNA GET
'Cookie: SSESSd4f3e89d4699e1d1a071aa37eab4fcEd=DWS4UqpaykI2y7q-HJXEzGN82AKHQYnWo5hbsqkAqiQ'
),
));
$result = curl_exec($curl);
curl_close($curl);
But I've noticed that there's the cookie in the CURLOPT_HTTPHEADER entry but I don't have any idea how POSTMAN generate this cookie.
Without this cookie or with a dumb string, the CURL response is always Invalid Signature
Postman is not generating cookies for you, and neither is curl/php. you either did some prior requests (usually GET to get cookies) requests to the website where you received some cookies, or gave the cookies to postman some other way.
since you're not showing us the real url, we can only speculate, but to take an example, here is how to get a session cookie for stackoverflow.com:
<?php
$ch=curl_init();
curl_setopt_array($ch,array(
CURLOPT_COOKIEFILE => "", // setting it to empty activates the curl cookie engine (its disabled by default.),
CURLOPT_URL => "https://stackoverflow.com/",
CURLOPT_RETURNTRANSFER => true,
));
$html=curl_exec($ch);
$cookies = (function($cookielist):array{
$cookies = array();
foreach($cookielist as $cookie_raw) {
$chunks = explode("\t", $cookie_raw);
//var_dump($chunks);
$cookie['domain'] = $chunks[0];
$cookie['secure'] = $chunks[1];
$cookie['path'] = $chunks[2];
$cookie['???todo_wtf_is_this'] = $chunks[3];
$cookie['expiration'] = $chunks[4];
$cookie['name'] = $chunks[5];
$cookie['value'] = $chunks[6];
$cookies[] = $cookie;
}
return $cookies;
})(curl_getinfo($ch, CURLINFO_COOKIELIST));
var_export($cookies);
prints something like
array (
0 =>
array (
'domain' => '#HttpOnly_.stackoverflow.com',
'secure' => 'TRUE',
'path' => '/',
'???todo_wtf_is_this' => 'FALSE',
'expiration' => '2682374400',
'name' => 'prov',
'value' => '9c06f038-9f70-bee8-2a64-b095656175d1',
),
)
which could be used like
// THE COOKIE I WANNA GENERATE
'Cookie: '. $cookies[0]["name"].'='.$cookies[0]["value"]
but this is very rarely done, usually you'd just use curl's built-in cookie engine to handle cookies automatically..

How to extract bitcoin address only from a block in the blockchain

I'm trying to extract the bitcoin address from the blockchain. To be more specific if you go to this link https://blockchain.info/btc/block/1 you would see that the bitcoin address on that block is "12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX"
What is the best way to extract that details using PHP/Json ?
take a look at blockchain.com/api/blockchain_api
you got everything there.
blockchain.info has an API to get block details.
blockchain.info API
Using https://blockchain.info/block-height/$block_height endpoint, you can pass $block_height as block number that you need.
Then by simple script like below, you can extract the addresses.
<?php
$blockTxs = getBlockTxs(1);
foreach ($blockTxs as $tx) {
foreach ($tx->out as $out)
{
var_dump($out->addr);
}
}
function getBlockTxs($height) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://blockchain.info/block-height/' . $height,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
return (json_decode($response))->blocks[0]->tx;
}

Unable to make the HTTP POST request with the AWS signature in drupal 8 / PHP

We are unable to make the HTTP POST request call to fetch the results and note that autherization type is AWS signature authorization.
In Drupal -8, we have tried with 'AWS connector' module but can not find the exact service for the HTTP POST request with the AWS signature authorization.
Notes:
I got some info on this at drupalize.me site.
<code>
$client = \Drupal::httpClient();
$request = $client->get('https://api.github.com/user', [
'auth' => ['username','password']
]);
$response = $request->getBody();
(Ref: https://drupalize.me/blog/201512/speak-http-drupal-httpclient)
</code>
The auth is for above is basic authentication. But I need for “AWS Signature”
We have tried the below curl code and not able to get the any result. Its showing the white blank screen without any errors.
<code>
$startTimestamp = time();
$amz = gmdate('Ymd\THis\Z', $startTimestamp);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-runtime.us-east-1.amazonaws.com/endpoint",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\n\t\"campaignArn\":\"arn:aws:test:us-east-1:12456:campaign/test\",\n\t\"numResults\":2,\n\t\"userId\":\"400\"\n}",
CURLOPT_HTTPHEADER => array(
'"authorization: AWS4-HMAC-SHA256 Credential=**********/20191205/us-east-1/Test/aws4_request,
SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-target,
Signature=' . $signature . '"',
'"cache-control: no-cache"',
'"content-type: application/json"',
'"host: test-runtime.us-east-1.amazonaws.com"',
'"x-amz-date:' . $amz . '"',
'"x-amz-target: getrecommendations"'
),
));
$result = curl_exec($curl);
if($result === false) {
echo "Error in cURL : " . curl_error($curl);
}
else {
echo 'no error'.$result;
}
Please check and share the valuable inputs / reference.

API Newbie - PHP Curl Call

I am new to API's so please be easy on me! My school has a ooen data platform API for anyone to use. So, I decided to get a user & key in order to test stuff out. The following code snippet is my script in order to print out the details of a course.
<?php
$APIUSER = “***”; //user value from your application
$APIKEY = “***”; //Api key value from your application
$url = "https://opendata.concordia.ca/API/v1/course/description/filter/000106";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HEADER => 0,
CURLOPT_USERPWD => $APIUSER . ":" . $APIKEY
));
$response = curl_exec($curl);
print($response);
?>
I tested my API user & API key on the $url page and it worked. Unfortunately, when I run the script on a local server, there is nothing printing. Am I missing something?

Categories