0

oAuth seems to work (SO CLOSE!)

I've downloaded the PHP SDK and modified the oauth sampleapp.php. It creates a login link that brings me to yahoo and I click "agree" then it redirects me back to the sampleapp.php page just fine. Here is my code:

CODE
<?php

require dirname(__FILE__).'/lib/Yahoo.inc';

error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', true);
YahooLogger::setDebug(true);
YahooLogger::setDebugDestination('LOG');

ini_set('session.save_handler', 'files');
session_save_path('/tmp/');
session_start();

define('OAUTH_CONSUMER_KEY', '<YOURS_GOES_HERE>');
define('OAUTH_CONSUMER_SECRET', '<YOURS_GOES_HERE>');
define('OAUTH_DOMAIN', '<YOURS_GOES_HERE>');
define('OAUTH_APP_ID', '<YOURS_GOES_HERE>');

if(array_key_exists("logout", $_GET)) {
YahooSession::clearSession();
header("Location: sampleapp.php");
}

$hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);

if($hasSession == FALSE) {

$callback = YahooUtil::current_url();
$auth_url = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback);

}
else {

$session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);

if($session) {

$consumer = new stdclass();
$consumer->key = OAUTH_CONSUMER_KEY;
$consumer->secret = OAUTH_CONSUMER_SECRET;

$nativeSession = new NativeSessionStore();
$token = $nativeSession->fetchAccessToken();

$client = new OAuthClient($consumer, $token, OAUTH_PARAMS_IN_HEADERS, OAUTH_SIGNATURE_HMAC_SHA1);

$request_url = 'http://api.del.icio.us/v2/posts/add';
$bookmark_url = 'http://www.tegdesign.com';
$parameters = array("url" => urlencode($bookmark_url), "description" => "test");

$response = $client->post($request_url,'TEXT',$parameters);

echo '<pre>';
print_r($response);
echo '</pre>';

}

}


if($hasSession == FALSE) {

echo sprintf("<a href=\"%s\" id=\"yloginLink\">Login</a>\n", $auth_url);

} else if($hasSession) {

echo "<p><a href=\"?logout\">Logout</a></p>";

}

?>


The response I receive back is:

CODE
Array
(
[method] => POST
[url] => http://api.del.icio.us/v2/posts/add
[code] => 401
[requestHeaders] => Array
(
[0] => Accept: application/json
[1] => Authorization: OAuth realm="yahooapis.com",oauth_version="1.0",oauth_nonce="<MINE_SHOWS_HERE>",oauth_timestamp="1289407587",oauth_consumer_key="<MINE_SHOWS_HERE>",oauth_token="<MINE_SHOWS_HERE>",oauth_signature_method="HMAC-SHA1",oauth_signature="<MINE_SHOWS_HERE>"
[2] => Content-Type: TEXT
)

[requestBody] => Array
(
[url] => http%3A%2F%2Fwww.tegdesign.com
[description] => test
)

[responseHeaders] => Array
(
[Date] => Wed, 10 Nov 2010 16:46:32 GMT
[WWW-Authenticate] => OAuth oauth_problem="signature_invalid", realm="yahooapis.com"
[Content-Type] => application/json
[Cache-Control] => private
[Age] => 0
[Transfer-Encoding] => chunked
[Connection] => keep-alive
[Server] => YTS/1.17.21
)

[responseBody] => {"error":{"lang":"en-US","description":"Please provide valid credentials"}}
)



Does anybody have any ideas why I'm not able to authenticate to Delicious and post a bookmark?

Thanks,

Tegan

by
1 Reply
  • Also I get the following error:


    Warning: First parameter must either be an object or the name of an existing class in /home/beblome/public_html/app/socialize/delicious/yos/lib/Yahoo.inc on line 1372

    Warning: First parameter must either be an object or the name of an existing class in /home/beblome/public_html/app/socialize/delicious/yos/lib/Yahoo.inc on line 1372
    0
This forum is locked.

Recent Posts

in Y!OS SDKs