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 .
bnnoor
  • 656
  • 2
  • 13
  • 31
  • I remove the user-agent but also not work . user-agent is my option and not nessary . question edit – bnnoor Jul 08 '16 at 10:48
  • You have replaced 'faxir_access_token' with your own token, right? – ajmedway Jul 08 '16 at 10:52
  • yes . I replace but not work but in "www.hurl.it" work prefect !!! – bnnoor Jul 08 '16 at 10:54
  • i think because my curl header set not correct – bnnoor Jul 08 '16 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? – ajmedway Jul 08 '16 at 11:15
  • Also, why are you using a mozilla user agent string? And where is `$this->client_id` being set? Have you just copied and pasted this chunk of code from some other website? You need to provide more information/code/context or nobody will be able to help you. – ajmedway Jul 08 '16 at 11:19
  • i check this code and access code and client id set right im sure headers not set correct and error is on header section . – bnnoor Jul 08 '16 at 11:22
  • how i can get this request header? – bnnoor Jul 08 '16 at 11:24

1 Answers1

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

Community
  • 1
  • 1
ajmedway
  • 1,492
  • 14
  • 28
  • Code:0,Error Number:60,Error String:SSL certificate problem: unable to get local issuer certificate – bnnoor Jul 08 '16 at 11:38
  • 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."}} – bnnoor Jul 08 '16 at 11:54
  • @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 – ajmedway Jul 08 '16 at 11:58