1

Problem with PHP SDK

I am trying to start testing the PHP SDK but I cannot get much out of it. It seems strange error and I wonder if anyone is having the same problems:

I have a simple code in PHP
QUOTE
<?php
// Include the PHP SDK to access library
include_once("yosdk/lib/Yahoo.inc");
// Your Consumer Key (API Key) goes here.
define('CONSUMER_KEY', "myconsumerKEY--");

// Your Consumer Secret goes here.
define('CONSUMER_SECRET', "myconsumerSECRET");

// Your application ID goes here.
define('APPID', "8nWCnY76");

$session = YahooSession::requireSession(CONSUMER_KEY,CONSUMER_SECRET,APPID);
?>



When I call this file in the browser I get:
<br />
<b>Warning</b>: array_key_exists() [<a href='function.array-key-exists'>function.array-key-exists</a>]: The second argument should be either an array or an object in <b>/home/lajme2/public_html/yahoo/yosdk/lib/Yahoo.inc</b> on line <b>1507</b><br />
<br />
<b>Warning</b>: array_key_exists() [<a href='function.array-key-exists'>function.array-key-exists</a>]: The second argument should be either an array or an object in <b>/home/lajme2/public_html/yahoo/yosdk/lib/Yahoo.inc</b> on line <b>1498</b><br />

<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/lajme2/public_html/yahoo/yosdk/lib/Yahoo.inc:1507) in <b>/home/lajme2/public_html/yahoo/yosdk/lib/Yahoo.inc</b> on line <b>341</b><br />


Any suggestions as what might be wrong?
I checked the Line 1507 and it seems a normal call on a return from the function below:
QUOTE
function hasAccessToken() {
1507: return array_key_exists("yosdk_at", $_SESSION) && (strlen($_SESSION["yosdk_at"]) > 0);
}

by
10 Replies
  • Try removing the app id from the require_session call (only input the first two arguments for consumer and secret keys)...see if that works. If not, make sure that nothing else is being echoed out to the screen (like spaces) because the header call will fair with that error if that's the case.

    Jonathan LeBlanc
    Technology Evangelist
    Yahoo! Developer Network
    Twitter: jcleblanc
    0
  • QUOTE (Jonathan LeBlanc @ Sep 15 2009, 02:21 PM) <{POST_SNAPBACK}>
    Try removing the app id from the require_session call (only input the first two arguments for consumer and secret keys)...see if that works. If not, make sure that nothing else is being echoed out to the screen (like spaces) because the header call will fair with that error if that's the case.

    Jonathan LeBlanc
    Technology Evangelist
    Yahoo! Developer Network
    Twitter: jcleblanc


    Thank you for the reply.
    I tried removing and still the same error.
    I also tried the code from: http://developer.yahoo.com/yos/code_exs/my...ource_code.html mysocial.php (by adding ofcourse a new API Key (OAuth consumer key)). This time I tried in another server and still the same error (first try on Debian , this time on CentOS).

    Can someone confirm that the examples work fine?
    0
  • QUOTE (Armand B @ Sep 15 2009, 02:28 PM) <{POST_SNAPBACK}>
    Thank you for the reply.
    I tried removing and still the same error.
    I also tried the code from: http://developer.yahoo.com/yos/code_exs/my...ource_code.html mysocial.php (by adding ofcourse a new API Key (OAuth consumer key)). This time I tried in another server and still the same error (first try on Debian , this time on CentOS).

    Can someone confirm that the examples work fine?

    Ah, in the mysocial.php the code is:
    $yahoo_session = YahooSession::requireSession(API_KEY, SHARED_SECRET);
    0
  • That's odd - the code that you are using is the same that I am for one of you apps. Can you try the following please:

    1. Remove all content for the app with the exception of the following. Test again and see if that loads:
    CODE
    <?php
    require_once('yosdk/lib/Yahoo.inc');

    //define constants to store your API Key (Consumer Key) and Shared Secret (Consumer Secret)
    define(CONSUMER_KEY,"KEY HERE");
    define(CONSUMER_SECRET,"KEY HERE");

    //initializes session and user
    $yahoo_session = YahooSession::requireSession(CONSUMER_KEY, CONSUMER_SECRET);
    $yahoo_user = $yahoo_session->getSessionedUser();
    ?>


    2. Do you have the most recent version of the PHP SDK? Just to make sure can you get the files directly from: http://github.com/yahoo/yos-social-php

    Try those two and see if it loads up.

    - Jon
    0
  • I was just speaking with one of my colleagues who brought up an issue that he gets when using the PHP SDK - one that produces errors like what you are seeing. It appears that in some instances this problem may come from the lack of specifying a session. If those previous two suggestions don't work, try adding the following to the top of the PHP block:

    session_start();

    That may be the issue.

    - Jon
    0
  • QUOTE (Jonathan LeBlanc @ Sep 16 2009, 09:04 AM) <{POST_SNAPBACK}>
    I was just speaking with one of my colleagues who brought up an issue that he gets when using the PHP SDK - one that produces errors like what you are seeing. It appears that in some instances this problem may come from the lack of specifying a session. If those previous two suggestions don't work, try adding the following to the top of the PHP block:

    session_start();

    That may be the issue.

    - Jon


    Hello Jon,
    I confirm that session_start(); was the problem.
    Now I can make use of the rest of the files.
    Thank you for your support!

    rgds,
    Armand
    0
  • Not a problem - thank you for letting me know what it was. Since this is the first time I've heard of this issue I'll try to find some way of integrating it into some FAQs in case anyone runs into the same blocker.

    - Jon
    0
  • The same issue met, and resolved:)

    Thanks so much!
    0
  • Bing, there was a recent revision to the PHP SDK to fix an OAuth issue. Can you please try downloading the SDK again from http://www.github.com/yahoo and give try again?

    That may solve the issue.

    - Jon
    0
  • QUOTE (Jonathan LeBlanc @ Oct 4 2009, 07:36 AM) <{POST_SNAPBACK}>
    Bing, there was a recent revision to the PHP SDK to fix an OAuth issue. Can you please try downloading the SDK again from http://www.github.com/yahoo and give try again?

    That may solve the issue.

    - Jon


    I encountered this error

    Warning: First parameter must either be an object or the name of an existing class in /data/www/Yahoo-GA/yahoo-lib/Yahoo.inc on line 1372

    Warning: First parameter must either be an object or the name of an existing class in /data/www/Yahoo-GA/yahoo-lib/Yahoo.inc on line 1372

    Warning: Cannot modify header information - headers already sent by (output started at /data/www/Yahoo-GA/yahoo-lib/Yahoo.inc:1372) in /data/www/Yahoo-GA/yahoo-lib/Yahoo.inc on line 343




    require_once('yahoo-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 local filesystem to store oauth credentials via php native sessions
    ini_set('session.save_handler', 'files');
    session_save_path('/tmp/');
    session_start();

    // Your Consumer Key (API Key) goes here.
    define('CONSUMER_KEY', "-YOU KEY-");

    // Your Consumer Secret goes here.
    define('CONSUMER_SECRET', "YOU SECRET");

    // Your application ID goes here.
    define('APPID', "vtJ78A34");

    //$session = YahooSession::requireSession(CONSUMER_KEY,CONSUMER_SECRET,APPID);

    $yahoo_session = YahooSession::requireSession(CONSUMER_KEY, CONSUMER_SECRET);



    // Fetch the logged-in (sessioned) user
    $user = $yahoo_session->getSessionedUser();

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


    $content = '<h1><yml:name> customized small view</h1>';

    var_dump($user->getProfile());
    var_dump($user->getContacts());
    0

Recent Posts

in Social Directory API