Http_code 301 redirect_url issue localhost authorize


#1

i have issue hunspot with redirection return 301 code

$ApiDataSet = array(
'client_id' => 'XXXXXX',
'scope' => 'contacts',
'redirect_uri' => 'http://localhost/mytask/account.php'
);

$header = array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded;charset=utf-8',
);

$endpoint = 'http://app.hubspot.com/oauth/authorize';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $ApiDataSet);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
@curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
print_r($info);


#3

Hi @Ankit,

What error are you receiving?


#4

some redirection issues, to same page redirect call.
so i solved Thanks Isaac_Takushi for the interest.

This is the my final code for this

$client_id = 'xxx-xxx-xxxx';

$client_secret = 'xxx-xxx-xxx';

$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';

$redirect_uri = $protocol.$_SERVER['HTTP_HOST'].'/'.$_SERVER['PHP_SELF'];

$url_auth = 'http://app.hubspot.com/oauth/authorize?client_id='.$client_id.'&scope=contacts%20automation&redirect_uri='.$redirect_uri;

Login


#5

I'm glad you sorted it out, @Ankit!


#6