tags:

views:

65

answers:

2

I'm trying to use cURL to do facebook authentication and here's what I have:

        $url = "https://graph.facebook.com/oauth/access_token";
        $postString = "?client_id=$client_id&redirect_uri=$redirect_uri&client_secret=$client_secret&code=$code";
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_FAILONERROR, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        //curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $postString);
        $response = curl_exec($curl);

but every time it just returns false.

I'm pretty new to using cURL so I could be making some beginner mistakes, but I'm confused as to why this isn't working at all.

Any help would be greatly appreciated!

A: 

This is probably too obvious and it may be a typo, but:

//curl_setopt($curl, CURLOPT_POST, 1);

Should be uncommented.

Jud Stephenson
I was just testing both GET and POST to see whether it made a difference, I happened to have just tested GET before I copy pasted the code here :)Thanks for the answer anyway!
machinemessiah
If I were you, I would debug like this: `FAILONERROR` should be taken out, or commented. And the '?' in the `$postString` taken out (I believe). Does it give any kind of response, or is `$response` empty?
Jud Stephenson
A: 

Remove the "?" from the beginning of your post string.. that should fix it!

zachallia