I have a very strange problem, here is my code :
function myFunction($id, $name, $secret) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.myurl.com/api');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query(
array(
'Client_id' => $id,
'Client_secret' => $secret, // $secret = Ve6UZ0cox=ry?2F9>qegmB:NCh?EQS?]cKmkjeHjS=3t1=E<RJ
'Client_name' => $name
)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$results = curl_exec($ch);
$results = json_decode($results, true);
print_r($results);
curl_close ($ch);
// curl_close($curl);
return $results['Token_type'].' '.$results['Access_token'];
}
The code above doesn't work, probably due to special chars in $secret.
But, when I directly write the $secret value, it works!
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query(
array(
'Client_id' => $id,
// Now, it works!
'Client_secret' => 'Ve6UZ0cox=ry?2F9>qegmB:NCh?EQS?]cKmkjeHjS=3t1=E<RJ'
'Client_name' => $name
)));
Conclusion:
'Client_secret' => $secret // Doesn't work
'Client_secret' => 'Ve6UZ0cox=ry?2F9>qegmB:NCh?EQS?]cKmkjeHjS=3t1=E<RJ' // Work!
And yes, I tried this: die($secret);, which displays Ve6UZ0cox=ry?2F9>qegmB:NCh?EQS?]cKmkjeHjS=3t1=E<RJ as well.
What can you do please? Thank you for helping. ;-)
Cheers,
Seb
Related
Why I'm having the above error in the following code, is the syntax is not ok,I'm working on authorization with Instagram.
public function getAccessTokeAndUserDetails($code){
$postFields = array(
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'grant_type' => "authorization_code",
'redirect_uri' => $this->redirectURI,
'code' => $code
);
$ch = curl_init();
curl_setopt($ch, option:CURLOPT_URL,value:"https://api.instagram.com/oauth/access_token");//line 28
curl_setopt($ch, option:CURLOPT_RETURNTRANSFER, value:1);
curl_setopt($ch, option:CURLOPT_SSL_VERIFYHOST, value:0);
curl_setopt($ch, option:CURLOPT_SSL_VERIFYPEER, value:0);
curl_setopt($ch, option:CURLOPT_POST, value:1);
curl_setopt($ch, option:CURLOPT_POSTFIELDS, $postFields);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response,assoc:true);
}
public function getAccessTokeAndUserDetails($code){
$postFields = array(
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'grant_type' => "authorization_code",
'redirect_uri' => $this->redirectURI,
'code' => $code
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.instagram.com/oauth/access_token");//line 28
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response,assoc:true);
}
option and value no need to be there. It's like placeholders in the documentation. Documentation refers to the position. It's a function so you need to know which values to pass to this function in order to work and most important in which order.
I wrote this code. I send data to $url = "https://upload.box.com/api/2.0/files/content", but i don't get a response. Maybe someone has also had this problem?
$absolutePath = 'home/my/path/uploads/media/ClientPDF/0001/01/c607bea86bdb42220bb49aac722b4a5eb44be3db.pdf';
$json = json_encode([
'name' => 'c607bea86bdb42220bb49aac722b4a5eb44be3db.pdf,
'parent' => ['id' => 7479666489] //parent folder
]);
$fields = [
'attributes' => $json,
'file' => #$absolutePath
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer MY_TOKEN_KEY'
'Content-Type:multipart/form-data'
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$response = curl_exec($ch);
var_dump(json_decode($response, true)); die;
var_dump - print nothing, i can't debug this request. Please, help me to solve this problem
I want to create a webhook url for pitifuller form by id here is my code i don't know what is my mistake
define('CLIENT_ID', 'client_id');
define('CLIENT_SECRET', 'client_secret');
define('REDIRECT_URL', 'redirect url'); // for testing, use the URL to this PHP file.
define('AUTHORIZE_URL', 'https://www.formstack.com/api/v2/oauth2/authorize');
define('TOKEN_URL', 'https://www.formstack.com/api/v2/oauth2/token');
$ch = curl_init(TOKEN_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'grant_type' => 'authorization_code',
'client_id' => CLIENT_ID,
'redirect_uri' => REDIRECT_URL,
'client_secret' => CLIENT_SECRET,
'id' => 'id', // here is my id
'url' => 'web_hook_url' // here is my webhook url which i want to create
)));
// oauth2 contains the the access_token.
$oauth2 = json_decode(curl_exec($ch));
You did mistake in your CURL call, currently you are pass post data in GET form and you need to pass Like this(POST form/:id/webhook), and you can do this:
$ch = curl_init('https://www.formstack.com/api/v2/form/your-form-id/webhook');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $oauth2->access_token
));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'id' => $_POST['id'],
'url' => 'http://www.getbravo.com/formstack/index.php',
'append_data' => '1'
)));
and you get response like this
$forms = json_decode(curl_exec($ch));
print '<pre>';
print_r($forms);
print '</pre>';
I have a few subscriptions. Time to time subscription ends and I start the ended subscription again.
Now, my most used subscriptions ended and I can't start again. I'm working in PHP. Nothing has changed in my code, but now I get error while trying to subscribe.
{"meta":{"error_type":"APISubscriptionError","code":400,"error_message":"Invalid response"}}
My other subscriptions are still active but 4 of them are failing. I couldn't fix it.
Edit - Code:
<?php
echo $_GET['hub_challenge'];
$client_id='XXXXX';
$client_secret='XXXXX';
$object = 'tag';
$aspect = 'media';
$object_id = 'XXXXX';
$verify_token='XXXXX';
$callback_url = 'http://XXXXX/callback.php';
$attachment = array(
'client_id' => $client_id,
'client_secret' => $client_secret,
'object' => $object,
'object_id' => $object_id,
'aspect' => $aspect,
'verify_token' => $verify_token,
'callback_url'=>$callback_url
);
$url = "https://api.instagram.com/v1/subscriptions/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close ($ch);
print_r($result);
Instagram sends a GET request to uour callback_url and wants you to response with hub.challenge.
I have the following code in php:
define("TOKEN_URL", "https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13");
$arrData = array(
'grant_type=client_credentials',
'client_id='.CLIENT_ID,
'client_secret='.urlencode(ACCESS_KEY),
'scope=urn%3aWindowsAzureMediaServices'
);
$arrHeader = array(
'Content-length:'.strlen($this->generateData($arrData))
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, TOKEN_URL);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->generateData($arrData));
curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeader);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$arrToken = json_decode($data);
I am unable to get the token code. Please can anyone check what could be wrong?
There could be a few issues:
You could simplify a few things and use http_build_query():
$data = http_build_query(array(
'grant_type' => 'client_credentials',
'client_id' => CLIENT_ID,
'client_secret' => ACCESS_KEY,
'scope' => 'urn:WindowsAzureMediaServices',
));
$ch = curl_init(TOKEN_URL);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (($res = curl_exec($ch)) === false) {
die(curl_error($ch));
}
$arrToken = json_decode($res);
If there's an error, the first thing to make sure is whether you have an updated list of CA certificates.