0

I've tried a few different things, but everything I can find isnt working. I have a photo URL, and am trying to access it with the appropriate authentication

  $service_url = 'photo URL';
  $curl = curl_init($service_url);
  curl_setopt($curl, CURLOPT_HTTPHEADER, array('Bearer code'));
  curl_setopt($curl, CURLOPT_USERPWD, "Username:Password"); 
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'GET'); // LINE 12

  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); 
  $curl_response = curl_exec($curl);
  $response = json_decode($curl_response);
  curl_close($curl);

  var_dump($response);

Obviously I'm trying to do a GET, but im not sure its working correctly. I'm also not sure that the

      curl_setopt($curl, CURLOPT_HTTPHEADER, array('Bearer code'));

line is working correctly.

Any ideas?

P.S. - The link is a https://

Thanks!

4
  • 1
    What is $curl_response after this is called? Commented Jun 20, 2014 at 22:27
  • Warning: curl_setopt() expects parameter 1 to be resource, null given in /web/com/140330164410217/main.php on line 12 object(stdClass)#1 (1) { ["error"]=> string(14) "not authorized" } So it looks like there is an error on the 'GET' line, and its still not being authorized correctly Commented Jun 20, 2014 at 22:28
  • The warning is because you're using $curl_handle instead of $curl on that line, no? Commented Jun 20, 2014 at 23:22
  • You shouldn't need it though, GET is default. I would remove it completely. When curl expects something to be done differently, it sometimes flakes out, even if your request seems perfectly reasonable (like setting "GET"). Commented Jun 20, 2014 at 23:23

1 Answer 1

1

I don't think this is a valid value for CURLOPT_HTTPHEADER

array('Bearer code')

You need a header name AND value, such as

array('Authorization: Bearer code')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.