Last active
September 24, 2019 13:25
-
-
Save eto4detak/c496d35f163afab5a825e1da99e7a440 to your computer and use it in GitHub Desktop.
php curl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
private static $bearer = "2MDaDp4eFyFqMkj33grHC1wDuSYZ8mso"; | |
static function getPurchaseData( $code ) { | |
//setting the header for the rest of the api | |
$bearer = 'bearer ' . self::$bearer; | |
$header = array(); | |
$header[] = 'Content-length: 0'; | |
$header[] = 'Content-type: application/json; charset=utf-8'; | |
$header[] = 'Authorization: ' . $bearer; | |
$verify_url = 'https://api.envato.com/v1/market/private/user/verify-purchase:'.$code.'.json'; | |
$ch_verify = curl_init( $verify_url . '?code=' . $code ); | |
curl_setopt( $ch_verify, CURLOPT_HTTPHEADER, $header ); | |
curl_setopt( $ch_verify, CURLOPT_SSL_VERIFYPEER, false ); | |
curl_setopt( $ch_verify, CURLOPT_RETURNTRANSFER, 1 ); | |
curl_setopt( $ch_verify, CURLOPT_CONNECTTIMEOUT, 5 ); | |
curl_setopt( $ch_verify, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); | |
$cinit_verify_data = curl_exec( $ch_verify ); | |
curl_close( $ch_verify ); | |
if ($cinit_verify_data != "") | |
return json_decode($cinit_verify_data); | |
else | |
return false; | |
} | |
function instagram_api_curl_connect($api_url, $instagram_data) | |
{ | |
// yo can follow this guide to http://www.benrlodge.com/blog/post/how-to-generate-an-instagram-access-token# | |
#1 first you need to create a Client in Instgram Developer Dashboard | |
// https://www.instagram.com/developer/clients/manage/ | |
#2 after you need to retrive a oAuth code for after get access_token | |
// https://www.instagram.com/developer/authentication/ | |
// change the params with your one and open link in browser | |
// https://www.instagram.com/oauth/authorize/?client_id=YOUR_CLIENT_ID_GOES_HERE&redirect_uri=THAT_REDIRECT_URI_YOU_GAVE&response_type=code | |
// at this point you have a code ex: http://www.YOUR_REDIRECT_LINK.com?code=asdf4a0c15d80bc54ddea32d6f1751 | |
// we need the code "asdf4a0c15d80bc54ddea32d6f1751" | |
# for use it in pour CURL request and obtain a access_token | |
// curl native commands | |
//curl -F 'client_id=CLIENT_ID' \ | |
// -F 'client_secret=CLIENT_SECRET' \ | |
// -F 'grant_type=authorization_code' \ | |
// -F 'redirect_uri=AUTHORIZATION_REDIRECT_URI' \ | |
// -F 'code=CODE' \ | |
// | |
/// curl with PHP | |
$uri = 'https://api.instagram.com/oauth/access_token'; | |
$data = [ | |
'client_id' => '213esdaedasdasd12...YOUR_CLINT_ID', | |
'client_secret' => 'a8b4aaf06c0da310...YOUR_CLIENT_SECRET', | |
'grant_type' => 'authorization_code', | |
'redirect_uri' => 'http://www.YOUR_REDIRECT_URL.it', | |
'code' => 'asdf4a0c15d80bc54ddea32d6f1751...retrivedCODE' | |
]; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $api_url); // uri | |
curl_setopt($ch, CURLOPT_POST, true); // POST | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $instagram_data); // POST DATA | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // RETURN RESULT true | |
curl_setopt($ch, CURLOPT_HEADER, 0); // RETURN HEADER false | |
curl_setopt($ch, CURLOPT_NOBODY, 0); // NO RETURN BODY false / we need the body to return | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // VERIFY SSL HOST false | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // VERIFY SSL PEER false | |
return json_decode(curl_exec($ch)); // execute curl | |
// $json_return = curl_exec( $connection_c ); // connect and get json data | |
// curl_close( $connection_c ); // close connection | |
// return json_decode( $json_return ); // decode and return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment