Search code examples
phpcurldeezer

How do I obtain the URL that a cURL request returns?


Trying to understand the Deezer API.

When I visit:

http://connect.deezer.com/oauth/auth.php?app_id=MY_APP_ID&redirect_uri=http://mydomain.me&perms=basic_access

I end up at http://mydomain.me/?code=8b69a9a6137094814375bcd5aa9a6c02

I'd like to parse the code variable out of the response. How can I do this with cURL?

Here's what I've tried:

$url = 'http://connect.deezer.com/oauth/auth.php?app_id=MY_APP_ID&redirect_uri=http://mydomain.me&perms=basic_access';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, true);

$a = curl_exec($ch);
$a = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);


echo "<pre>"; 
var_dump($a); 
die();

Solution

  • You have errors in your code

    These 2 lines should have $ch for the curl handle

    curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($c, CURLOPT_HEADER, true);
    

    The link you posted redirects to deezer.com/soon.php.