0

fetching folder ot user info via oauth

hello,

i really starting to enjoy the YMClient class and the work process with it smile.gif so thanks for that.

my problem now is that i am getting 'null' all the time.

this is what i am doing in my callBackScript.php:
CODE
$tokens	= array('oauth_token'=>$_GET['oauth_token'],'oauth_verifier'=> $_GET['oauth_verifier'],'oauth_token_secret'=>$tokenSecret);
$ymc = new YMClient($key,$secret);
$accessToken= $ymc->oauth_get_access_token($tokens);
$params = new stdclass(); // Empty params attribute
$params->fid = 'Inbox';
$params->startInfo = 0;
$params->numInfo = 10;
$results = $ymc->ListMessages($params,$accessToken);
var_dump($results); //the output is null :(


in the YMClient class it goes to here:

CODE
function __call($method, $arguments) {
$this->oaRefreshedToken = null;

list ($params, $tok) = $arguments;

ob_start();
echo "\nthis is method: $method";
echo "\nthis is arguments: ";print_r($arguments);
echo "\nthis is params: ";var_dump($params);
echo "\nthis is tok: ";print_r($tok);
$string = ob_get_contents();
ob_clean();
oauthEmail::writeToLogFile($string);


if(!$tok) {
throw new YMClientException("Missing oauth access token", 0, null);
}

$request = new stdclass();
$request->method = $method;
$request->params = $params;

// Create a loop around the cascade request in case
// the access token needs to be refreshed.
for($attemptNo = 0; $attemptNo < 2; $attemptNo++) {
$ch = curl_init(JSON11_ENDPOINT_URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json',
$this->__build_oauth_header($tok)
));
$rawresponse = curl_exec($ch);
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$responseContentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);

if($responseContentType === "application/json") {
if($rawresponse == "") {
throw new YMClientException("Empty response", 0, "The Ymail webservice returned an empty response");
}

$response = json_decode($rawresponse);

// Cascade returned an "unauthorized" response. Try to refresh the access token
if($responseCode == 401) {

// The token expired, attempt to refresh it
if(isset($response->error->description) && preg_match("/token_expired/", $response->error->description)) {
$tok = $this->__oauth_refresh_access_token($tok);
$this->oaRefreshedToken = $tok;
}

// Some other error occured. Forward along info about it.
else {
throw new YMClientException("Ymail request failed", $responseCode, $response);
}
}

else {
return $response->result;
}
}

else {
// Cascade returned a malformed response. Forward along info about it.
throw new YMClientException("Ymail request failed", $responseCode, "Bad response from Ymail: HTTP $responseCode, Content-Type: $responseContentType");
}
}
}


in my log file i see that everything is OK i mean $tok is set and the method is ListMessages
also nothing throw error of the class.

please tell me what i am doing wrong here.
and what is the right way to debug it

thanks
Elad

by
6 Replies
  • Hi Elad,

    You can actually dump the response from the server. Mostly you will see
    something like:

    {"result":null,"error":{"code":"Client.InputInvalid","message":"Submitted ListMessages is of incorrect type: string","detail":null}}

    This means that you don't send the right parameters to the Mail API.

    You can then output the JSON string you send to the server which looks like

    {"method":"ListMessages","params":{"fid":"Inbox","startInfo":0,"numInfo":10}}

    If you check the API document:
    http://developer.yahoo.com/mail/docs/user_...PCSampleRequest
    you can see that the "params" should be an ARRAY. So the correct
    request string is:

    {"method":"ListMessages","params":[{"fid":"Inbox","startInfo":0,"numInfo":10}]}

    Please note the extra "[]" pair after "params".

    Therefore you will have to modify your code like this:

    $param = new stdclass(); // Empty params attribute
    $param->fid = 'Inbox';
    $param->startInfo = 0;
    $param->numInfo = 10;
    $params[] = $param;
    $results = $ymc->ListMessages($params,$accessToken);

    Please try it and let us know if you still see any issue.

    Thanks,
    Yu Wang
    0
  • QUOTE (omiga @ Apr 15 2010, 01:42 PM) <{POST_SNAPBACK}>
    Hi Elad,

    You can actually dump the response from the server. Mostly you will see
    something like:

    {"result":null,"error":{"code":"Client.InputInvalid","message":"Submitted ListMessages is of incorrect type: string","detail":null}}

    This means that you don't send the right parameters to the Mail API.

    You can then output the JSON string you send to the server which looks like

    {"method":"ListMessages","params":{"fid":"Inbox","startInfo":0,"numInfo":10}}

    If you check the API document:
    http://developer.yahoo.com/mail/docs/user_...PCSampleRequest
    you can see that the "params" should be an ARRAY. So the correct
    request string is:

    {"method":"ListMessages","params":[{"fid":"Inbox","startInfo":0,"numInfo":10}]}

    Please note the extra "[]" pair after "params".

    Therefore you will have to modify your code like this:

    $param = new stdclass(); // Empty params attribute
    $param->fid = 'Inbox';
    $param->startInfo = 0;
    $param->numInfo = 10;
    $params[] = $param;
    $results = $ymc->ListMessages($params,$accessToken);

    Please try it and let us know if you still see any issue.

    Thanks,
    Yu Wang


    thanks Yu Wang,

    i am now getting: 401 - Please provide valid credentials. - token_rejected.

    what can i do?
    0
  • QUOTE (Test @ Apr 17 2010, 11:30 PM) <{POST_SNAPBACK}>
    thanks Yu Wang,

    i am now getting: 401 - Please provide valid credentials. - token_rejected.

    what can i do?



    cancel that question, i forgot to remove json_encode() from my $acessToken.
    its working.

    something else that i want to know:

    is there a limit for how many hits i should do?
    if i understood correctly, the access token is valid for one hour, but with oauth_authorization_expires_in i can use it for another 24 hours.

    that means that the user will have grant me access after 24 hours again? can i modify this time?

    thanks for the help.
    Elad
    0
  • Hi Elad,

    As long as your requests don't look abusive, they won't
    be blocked. :)Yu Wang
    0
  • QUOTE (omiga @ Apr 18 2010, 02:26 PM) <{POST_SNAPBACK}>
    Hi Elad,

    As long as your requests don't look abusive, they won't
    be blocked. :)my plan is to check for user new emails every 60-180 seconds, is that abusive?
    0
  • Hi Elad,

    I think that interval may be OK. Your code can be designed
    to be more robust: In case you get some error saying your
    process cannot be processed, then you can increase the check
    interval.

    Thanks,
    Yu Wang
    0

Recent Posts

in OAuth General Discussion YDN SDKs