0

OAuth is not working properly

Hi All,

We have tested the OAuth using the PHP SDK, but the YahooSession::requireSession() always return null.
We had properly providing API Key,Shared Secret,Application ID and also we had configured the Consumer Key to
access by selecting proper check box.
But still getting null value as session.

Looking forward for any help.

Thanks,

Karamveer.

by
5 Replies
  • A few things - have you checked the consumer key to make sure that it is completely the same? Sometimes if you manually copy the keys there are a few dashes that get left off. Also, have you created a profile at profiles.yahoo.com? If neither of those are the cause can you please post your sample code that is failing? I'll take a look.

    Jonathan LeBlanc
    Technology Evangelist
    Yahoo! Developer Network
    Twitter: jcleblanc
    0
  • QUOTE (Jonathan LeBlanc @ Nov 30 2009, 01:10 PM) <{POST_SNAPBACK}>
    A few things - have you checked the consumer key to make sure that it is completely the same? Sometimes if you manually copy the keys there are a few dashes that get left off. Also, have you created a profile at profiles.yahoo.com? If neither of those are the cause can you please post your sample code that is failing? I'll take a look.

    Jonathan LeBlanc
    Technology Evangelist
    Yahoo! Developer Network
    Twitter: jcleblanc



    Hi Jonathan! thanks for the quick response.
    Yes i have verified the key and secret number of times,They are perfectly fine.I also tried logging into "profiles.yahoo.com" with my yahoo id.No problem there too.
    And this issue has become headache since i am onto this for quiet a while now.

    here is the code:

    <?php

    // Include the YOS library.
    require dirname(__FILE__).'/../lib/Yahoo.inc';

    // debug settings
    error_reporting(E_ALL | E_NOTICE); # do not show notices as library is php4 compatable
    ini_set('display_errors', true);
    YahooLogger::setDebug(true);
    YahooLogger::setDebugDestination('LOG');

    // use memcache to store oauth credentials via php native sessions
    ini_set('session.save_handler', 'files');
    session_save_path('/tmp/');
    session_start();

    // Make sure you obtain application keys before continuing by visiting:
    // https://developer.yahoo.com/dashboard/createKey.html

    //code10k
    define('OAUTH_CONSUMER_KEY', 'dj0yJmk9VGZwUVFldVM5QUxCJmQ9WVdrOVRXNXpWekZITnpZbWNHbzlPVFV5TURBeU56YzImcz1j
    b25zdW1lcnNlY3JldCZ4PTA0');
    define('OAUTH_CONSUMER_SECRET', 'bd75cace681afd62f4524b0ab449c103ecf90da0');
    define('OAUTH_DOMAIN', 'code10.a1technology.asia');
    define('OAUTH_APP_ID', 'MnsW1G76');






    if(array_key_exists("logout", $_GET)) {
    // if a session exists and the logout flag is detected
    // clear the session tokens and reload the page.
    YahooSession::clearSession();
    header("Location: sampleapp.php");
    }

    // check for the existance of a session.
    // this will determine if we need to show a pop-up and fetch the auth url,
    // or fetch the user's social data.
    $hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);

    //echo "hasSession :<br>";var_dump($hasSession);
    YahooLogger::setDebug(true);
    if($hasSession == FALSE) {
    // create the callback url,
    $callback = YahooUtil::current_url()."?in_popup";
    //echo "<br>".$callback;
    // pass the credentials to get an auth url.
    // this URL will be used for the pop-up.
    $auth_url = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback);
    //echo "auth url :<br>";var_dump($auth_url);

    }
    else {
    // pass the credentials to initiate a session
    $session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);

    //echo "session :<br>";var_dump($session);exit;
    // if the in_popup flag is detected,
    // the pop-up has loaded the callback_url and we can close this window.
    if(array_key_exists("in_popup", $_GET)) {
    close_popup();
    exit;
    }

    // if a session is initialized, fetch the user's profile information
    if($session) {
    // Get the currently sessioned user.
    $user = $session->getSessionedUser();

    // Load the profile for the current user.
    $profile = $user->getProfile();
    }
    }

    /**
    * Helper method to close the pop-up window via javascript.
    */
    function close_popup() {
    ?>
    <script type="text/javascript">
    window.close();
    </script>
    <?php
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <html>
    <head>
    <title>YOS Social Platform Sample Application</title>

    <!-- Combo-handled YUI JS files: -->
    <script type="text/javascript" src="http://yui.yahooapis.com/combo?2.7.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="popupmanager.js"></script>

    <!-- Combo-handled YUI CSS files: -->
    <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?2.7.0/build/reset-fonts-grids/reset-fonts-grids.css&2.7.0/build/base/base-min.css">
    </head>
    <body>
    <?php
    if($hasSession == FALSE) {
    // if a session does not exist, output the
    // login / share button linked to the auth_url.
    echo sprintf("<a href=\"%s\" id=\"yloginLink\"><img src=\"http://l.yimg.com/a/i/ydn/social/updt-spurp.png\"></a>\n", $auth_url);
    }
    else if($hasSession && $profile) {
    // if a session does exist and the profile data was
    // fetched without error, print out a simple usercard.
    echo sprintf("<img src=\"%s\"/><p><h2>Hi <a href=\"%s\" target=\"_blank\">%s!</a></h2></p>\n", $profile->image->imageUrl, $profile->profileUrl, $profile->nickname);

    if($profile->status->message != "") {
    $statusDate = date('F j, y, g:i a', strtotime($profile->status->lastStatusModified));
    echo sprintf("<p><strong>&#8220;</strong>%s<strong>&#8221;</strong> on %s</p>", $profile->status->message, $statusDate);
    }

    echo "<p><a href=\"?logout\">Logout</a></p>";
    }
    ?>
    <script type="text/javascript">
    var Event = YAHOO.util.Event;
    var _gel = function(el) {return document.getElementById(el)};

    function handleDOMReady() {
    if(_gel("yloginLink")) {
    Event.addListener("yloginLink", "click", handleLoginClick);
    }
    }

    function handleLoginClick(event) {
    // block the url from opening like normal
    Event.preventDefault(event);

    // open pop-up using the auth_url
    var auth_url = _gel("yloginLink").href;
    PopupManager.open(auth_url,600,435);
    }

    Event.onDOMReady(handleDOMReady);
    </script>
    </body>
    </html>



    Following lines return null:

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

    application URL:
    http://code10.a1technology.asia/test.yahoo...e/sampleapp.php


    Thanks
    0
  • Hi,
    When i checked my apache error log it tells me this:

    APACHE ERRORS
    Mon Nov 30 09:27:00 2009] [error] [client 202.164.41.135] ERROR - Failed to create request token: timestamp_refused
    [Mon Nov 30 09:27:00 2009] [error] [client 202.164.41.135] ERROR - Failed to create request token

    Can u tell me what to do about this?

    Thanks
    karam
    0
  • Hi,
    there was an issue due to the timestamp.
    It works fine now.
    But how do we get to edit and update the contacts.
    Can you please help.

    i have filled up the form required for that which was mentioned on this link.
    http://developer.yahoo.com/social/contacts/

    This is where i filled up the form
    http://developer.yahoo.com/register/

    Is that all i need to do.?

    Please help!!

    Thanks
    karamveer.
    0
  • QUOTE (Karamvir @ Dec 1 2009, 12:51 PM) <{POST_SNAPBACK}>
    Hi,
    there was an issue due to the timestamp.
    It works fine now.
    But how do we get to edit and update the contacts.
    Can you please help.

    i have filled up the form required for that which was mentioned on this link.
    http://developer.yahoo.com/social/contacts/

    This is where i filled up the form
    http://developer.yahoo.com/register/

    Is that all i need to do.?

    Please help!!

    Thanks
    karamveer.


    Karamvir,

    Could you post the whole source code and what you did in order to make it work? I can't seem to get the sampleapp to work (It keeps returning null) and I'm completely clueless as to how to fix it.
    0
  • QUOTE (Carlos @ Dec 15 2009, 07:21 PM) <{POST_SNAPBACK}>
    Karamvir,

    Could you post the whole source code and what you did in order to make it work? I can't seem to get the sampleapp to work (It keeps returning null) and I'm completely clueless as to how to fix it.


    Hello Karanvir,

    I am getting the same Null value for the those two functions.
    I am new to PHP.
    I dont know about the timestamp problem.
    can you please post your working code for sampleapp.php?

    thanks,
    Prakash
    0
  • QUOTE (Prakash @ Feb 1 2010, 10:33 PM) <{POST_SNAPBACK}>
    Hello Karanvir,

    I am getting the same Null value for the those two functions.
    I am new to PHP.
    I dont know about the timestamp problem.
    can you please post your working code for sampleapp.php?

    thanks,
    Prakash


    We are also experiencing this problem.

    The hasSession always returns NULL. Are there any server requirements? Coz we've tried test in another server and it works perfectly.
    0
  • Hello !
    Same problem here ! I'm using source provided here http://developer.yahoo.com/yos/code_exs/ex...s/mysocial.phps

    Created my test app on developer.yahoo.com/dashboard but I receive the error:

    Fatal error: Call to a member function getSessionedUser() on a non-object in (..)


    CODEBOX
        // Initializes session and redirects user to Yahoo! to sign in and then authorize app
    $yahoo_session = YahooSession::requireSession(API_KEY, SHARED_SECRET);

    // The YahooSession object $yahoo_session uses the method getSessionedUser to get a YahooUser object $yahoo_user
    $yahoo_user = $yahoo_session->getSessionedUser();


    I'm using constants:
    CODEBOX
    define("API_KEY", "dj0yJmk9VTBHVlVQb0tCWnpCJmQ9W(...)9uc3VtZXJzZWNyZXQmeD0wNQ--");
    define("SHARED_SECRET", "02ac5441b(..)8447e36dbe04eb1");


    but I already try to use Application ID with Customer Secret and others combinations...
    No errors at Apache's error_log, too.

    Any ideas ?
    Thanks guys !
    0
  • I've made some debugs and here the results:

    API_KEY as Application ID
    SHARED_SECRET as Consumer Key

    Curl returns: oauth_problem=consumer_key_unknown


    API_KEY as Consumer Key
    SHARED_SECRET as Consumer Secret

    Curl returns: Custom port is not allowed or the host is not registered with this consumer key.

    API_KEY as Application ID
    SHARED_SECRET as Consumer Secret

    Curl returns: oauth_problem=consumer_key_unknown

    Yes, I'm trying from my localhost.


    well... what's the real trouble ? Keys is corrects, so.. I don't know what's the problem :/
    0

Recent Posts

in OAuth General Discussion YDN SDKs