0

OAuth for YDN Download Attachment

Hello, I have set up an application on YDN and have the secret, key, and application ID. I have trying unsuccessfully using different OAuth libraries for PHP to get a request_token. Most of the code from common.php is below:

$debug = true;
$base_url = "http://onedev.freehostia.com/Download_Attachment/jcleblanc-oauth-php-3-legged/complete.php";
$request_token_endpoint = 'https://api.login.yahoo.com/oauth/v2/get_request_token';
$authorize_endpoint = 'https://api.login.yahoo.com/oauth/v2/request_auth';
$oauth_access_token_endpoint = 'https://api.login.yahoo.com/oauth/v2/get_token';

/***************************************************************************
* Function: Run CURL
* Description: Executes a CURL request
* Parameters: url (string) - URL to make request to
* method (string) - HTTP transfer method
* headers - HTTP transfer headers
* postvals - post values
**************************************************************************/
function run_curl($url, $method = 'GET', $headers = null, $postvals = null){
$ch = curl_init($url);

if ($method == 'GET'){
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
} else {
$options = array(
CURLOPT_HEADER => true,
CURLINFO_HEADER_OUT => true,
CURLOPT_VERBOSE => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $postvals,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_TIMEOUT => 3
);
curl_setopt_array($ch, $options);
}

$response = curl_exec($ch);
curl_close($ch);

return $response;
}

Additional code from index.php is below:

require_once "OAuth.php"; //oauth library
require_once "common.php"; //common functions and variables

//initialize consumer
$consumer = new OAuthConsumer($key, $secret, NULL);

//prepare to get request token
$sig_method = new OAuthSignatureMethod_HMAC_SHA1();
$parsed = parse_url($request_token_endpoint);
$params = array('oauth_callback' => $base_url);

//sign request and get request token
$req_req = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $request_token_endpoint, $params);
$req_req->sign_request($sig_method, $consumer, NULL);
$req_token = run_curl($req_req->to_url(), 'GET');

I have tried to echoed $req_token and the value is empty/NULL. I have tested the URL in the address bar and it comes back with a 404 error message. If additional code is needed, please let me know and I will provide.

I have reviewed the OAuth library code and other examples on the Web but for whatever reason, I cannot get past the first step of getting the token, so if someone could help me to understand what I am doing wrong it would be very much appreciated as I am new to using YDN.

Thank you.

by
0 Replies

Recent Posts

in PHP Development