Wednesday, 15 January 2014

php - Trouble Using Curl To OAUTH Foursquare -



php - Trouble Using Curl To OAUTH Foursquare -

i logging user in this,

<?php header("location: https://foursquare.com/oauth2/authenticate?client_id=foofoofoo&response_type=code&redirect_uri=http://www.example.com/sandbox/fsaccept.php"); exit(0); ?>

i redirecting take page token

<?php $cur = curl_init("https://foursquare.com/oauth2/access_token ?client_id=foofoo &client_secret=foofoo &grant_type=authorization_code &redirect_uri=http://www.example.com/fsaccept.php &code=code"); $cur; $fsresponse = json_decode('{ access_token: access_token }', true); header("location: http://www.example.com/sandbox"); ?>

then redirecting home page , var_dump $fsresponse

this appears in var_dump,

<?php var_dump("$fsresponse"); ?> string(0) ""

i think might setting wrong when in fsaccept.php

your json string you're trying json_decode() not valid json, json_decode() homecoming boolean false signify failure.

you don't store $fsresponse anywhere, 1 time script exits, value's lost. should go $_session can preserved next request.

all boils downwards to: $fsresponse in curl script useless, because json bad. useless variable lost when script exits. , $fsresponse in var_dump() script has absolutely no relation 1 in curl script, other sharing same name.

so yes, you're getting string(0) {} because $fsresponse undefined, , "$fsresponse" wraps empty string around undefined variable.

php curl

No comments:

Post a Comment