0

I want send headers with curl to https site to get user info . but nothing return . i change headers but not work :( . but when i use this site for online request work right . below is my code

$api_url = 'https://api.fax.ir/v1/accounts/selfe';
    $accessToken = get_option('faxir_access_token');
    $ch = curl_init($api_url);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Authorization: Bearer '.$accessToken,
        'x-faxir-clientid: '.$this->client_id
    ));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch,CURLOPT_VERBOSE,1);
    $output = curl_exec($ch);
    curl_close($ch);
    echo $output;

I know maybe headers set is incorect but i don know how change header? i googled and test many ways but all not work :( . sorry for my poor english .

  • top code return nothing .
8
  • I remove the user-agent but also not work . user-agent is my option and not nessary . question edit Commented Jul 8, 2016 at 10:48
  • You have replaced 'faxir_access_token' with your own token, right? Commented Jul 8, 2016 at 10:52
  • yes . I replace but not work but in "www.hurl.it" work prefect !!! Commented Jul 8, 2016 at 10:54
  • i think because my curl header set not correct Commented Jul 8, 2016 at 10:56
  • You need to seek some support from the API provider. Surely they provide some examples for how to obtain data from their endpoints? Commented Jul 8, 2016 at 11:15

1 Answer 1

1

Further to our comments exchange, you will need to do some debugging - try this, then write what you see in comments below. I will update this answer once I have seen your comment.

$api_url = 'https://api.fax.ir/v1/accounts/selfe';
$accessToken = get_option('faxir_access_token');
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer '.$accessToken,
    'x-faxir-clientid: '.$this->client_id
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_VERBOSE,1);
$output = curl_exec($ch);
echo "Code:".curl_getinfo($ch, CURLINFO_HTTP_CODE)."<br>";
echo "Error Number:".curl_errno($ch)."<br>";
echo "Error String:".curl_error($ch);
curl_close($ch);
echo $output;

OK, thanks for checking - I suggest trying this: https://stackoverflow.com/a/21114601/2429318

Sign up to request clarification or add additional context in comments.

3 Comments

Code:0,Error Number:60,Error String:SSL certificate problem: unable to get local issuer certificate
after edit and add pem file return : Code:403,Error Number:0,Error String:{"data":null,"error":{"domain":"authorization","code":"unauthorized","message":"You are not authorized to fetch user information."}}
@user3243573 - Excellent! You are now in communication with the API and getting data responses, so your problem is solved. The 403 error indicates you do not have permissions to access data at that endpoint with the credentials/token you have, but you need to seek help from the API provider for that. Please could you upvote and accept my answer? Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.