I was trying to install the Facebook PHP sdk through Libraries, and I received this error on the Status report for my site:

Notice: Undefined offset: 1 in libraries_get_version() (line 723 of /path/to/libraries.module).

After looking at the code, I was able to quickly correct this. I've attached a patch. This was problematic in both 7.x-2.0-alpha1 and the dev 2.0 dev version of the module.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

giorgio79’s picture

Status: Active » Reviewed & tested by the community
amitaibu’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
920 bytes

Patch created to apply to git.

Status: Needs review » Needs work

The last submitted patch, 1318946-libraries-offset-2.patch, failed testing.

azin’s picture

Status: Needs work » Needs review

#2: 1318946-libraries-offset-2.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 1318946-libraries-offset-2.patch, failed testing.

tstoeckler’s picture

Project: Libraries API » Facebook Connect

As you can see by the failing tests, returning $version[1] is the expected behaviour. I.e. the pattern you specify for libraries_get_version() should not be the entire version itself, but that should be the first sub-match, i.e. the first pair of parentheses.
Looking at the PHPDoc for libraries_get_version, though, that should probably be documented more clearly. The bug lies in the integrating module, though.

I looked at the code, and the following should do:

  function fbconnect_libraries_info() {
    // Returns an associative array, with information about external library
    $libraries['facebook-php-sdk'] = array(
      'name' => 'Facebook PHP SDK',
      'vendor url' => 'https://github.com/facebook/php-sdk',
      'download url' => 'https://github.com/facebook/php-sdk/tarball/v3.1.1',
      'version arguments' => array(
        'file' => 'readme.md',
        // Best practice: Document the actual version strings for later reference.
        // 3.1.1: Facebook PHP SDK (v.3.1.1), filters for 3.x.x versions
-        'pattern' => '/Facebook PHP SDK \(v.3.\d.\d\)/',
+        'pattern' => '/Facebook PHP SDK \(v.(3.\d.\d)\)/',
        'lines' => 10,
      ),
      // supported library version, including relevant files
      'versions' => array(
-       'Facebook PHP SDK (v.3.1.1)' => array(
+       '3.1.1' => array(
          'files' => array(
            'php' => array(
              'src/base_facebook.php',
              'src/facebook.php',
            ),
          ),
        ),
      ),
    );
    return $libraries;
  }

This is untested, though.

tstoeckler’s picture

I opened #1323530: Document libraries_get_version() pattern matching more explicitly. for the docs issue in Libraries API. See you there! :)

bryanzera’s picture

Fixing the pattern per tstoeckler's post worked for us

WhiteX’s picture

tstoeckler's method worked here too, but now I got other error :/ (exactly this)
Thanks

ricardo_reyes’s picture

tstoeckler et al,

I have edited the fbconnect.module as you explained on post #6. But my drupal system can't find the Facebook PHP sdk.

Do I still have to change the libraries.module to return $version[1]; or retur $version[0]; as others have indicated?
http://drupal.org/files/libraries_offset_fix.patch

If you or anyone please explain the ultimate solution. This forum has too many patches and alternative approaches. Your help is much appreciated.

Thanks.

tstoeckler’s picture

In theory my "patch" should be enough to make it work. I didn't test it, though, although for @bryanzera and @WhiteX it seemed to have worked.

FR6’s picture

Patch at #6 solved my problem on Drupal 7.9.
Thank you tstoeckler!

stenjo’s picture

Patch at #6 solved my problem too - using libraries 2.x-dev

JamesAn’s picture

Priority: Normal » Major
Status: Needs work » Needs review

I've independently confirmed the proposed fix in #1318946-6: Notice: Undefined offset: 1 in libraries_get_version(). It is indeed a bug in how hook_libraries_info was implemented. (I also agree that the hook_libraries_info documentation still requires you to inspect code and examples to figure it out.)

Details of my explanation can be found at #1318296-25: Facebook PHP library not found. I've marked that issue as a duplicate of this one, since the fix was first proposed here.

Since this bug prevents the module from functioning completely, I'm marking this as major, as recommended in the Issue queue handbook. Yet, I'm attaching a patch, so I hope this issue will get RTBC'd, patched up, and shipped out in a release soon so we can use the module without patching it ourselves.

JamesAn’s picture

-_- Of course, I forgot to attach the patch. Voila.

jenil27’s picture

I am still getting

PHP Fatal error:  Call to a member function getUser() on a non-object in sites/all/modules/fbconnect/fbconnect.module on line 408
  
csedax90’s picture

same problem...

PHP Fatal error: Call to a member function getUser() on a non-object in sites/all/modules/fbconnect/fbconnect.module on line 408

danohnesorg’s picture

Also after commit http://drupalcode.org/project/libraries.git/commit/c5515bd and patch from #6 the SDK seems be found correctly.

ricardo_reyes’s picture

I think my only problem now is the facebook-php-skd setup.

Do you have any specific direction on how the libarary should be setup in the Drupal7 structure?

1) sites/all/libraries/facebook-php-sdk/src/facebook.php
or
2) sites/all/modules/libraries/facebook-php-sdk/src/facebook.php
or
3) /sites/all/modules/fbconnect/facebook-php-sdk/src/facebook.php
or
4) ?

Or should the facebook-php-sdk folder be named to "php-sdk" as explained by facebook.

http://developers.facebook.com/docs/reference/php/

Your help is much appreciated.

tstoeckler’s picture

According to the hook_libraries_info() definition 1) should be correct.

bartl’s picture

(note: this is a reply to #6)

Pedantically speaking: in your pattern, the dots should be preceded by a backslash. A dot on itself matches any character, while the idea here is to match only dots.

Sjarsena’s picture

the patch that #6 did worked just take the one from #15 and patch that module. Working with libraries-2.x-dev

xaqrox’s picture

@19 - Option 1!

Also, the patch in #15 (explained in #6) fixed this for me too. Don't forget to clear your caches!

pointdexter02’s picture

I am also getting the error from #16 and #17 above

PHP Fatal error: Call to a member function getUser() on a non-object in sites/all/modules/fbconnect/fbconnect.module on line 408

It happens when I enable the "facebook login" block into a region.

Anybody figure this one out yet?

damien_vancouver’s picture

Status: Needs review » Reviewed & tested by the community

@Rico6xRico, yes it's option 1. I had to rename my "php-sdk" folder I got by git clone'ing the Facebook library to "facebook-php-sdk" and apply the patch from #15 (and finally clear your caches) before drupal would see the library in my Status report.

It appears many people have reported success here with the patch from #15. I started from scratch today and can verify that it is still an open issue with the latest 7.0-2.0-alpha2 version of Libraries and that the fix still works.

I'm therefore marking this as reviewed & tested by the community, specifically meaning the patch from #15.

tstoeckler’s picture

Status: Reviewed & tested by the community » Needs work

Pedantically speaking: in your pattern, the dots should be preceded by a backslash. A dot on itself matches any character, while the idea here is to match only dots.

Needs work for that?

cleaver’s picture

Status: Needs work » Needs review
FileSize
766 bytes

added the backslashes to the regex

damien_vancouver’s picture

Status: Needs review » Reviewed & tested by the community

New patch from #27 applies cleanly and works for me still. Setting back to reviewed & tested!

inkage’s picture

Hi,

Doesn't work for me
> Fresh latest Drupal 7 install
> Got the latest version of dev fbconnect + success patch from 27
> Latest dev version of Librairies
Still not found...

Cheers.

damien_vancouver’s picture

Status: Reviewed & tested by the community » Needs work

@inkage,

You're correct that the patch no longer works against Libraries v7.x-2.x-dev.

The dreaded "Notice: Undefined offset: 1 in libraries_get_version()" error message has returned.

A Workaround: You can download and install Libraries 7.x-2.0-alpha2, and then the patch from #27 should work. (remember your Facebook SDK must be named "facebook-php-sdk", ie. sites/all/libraries/facebook-php-sdk )

Meanwhile, we must make this work against the Libraries -dev. Setting back to needs work.

inkage’s picture

@damnien
Cheers, working by changing the lib, thanks mate !
> I just don't have the button displaying in the default logging box now :/

Thanks again.

cjs_’s picture

Not sure what to do at this point.

Have applied the latest patch to libraries.module and fbconnect.module, flushed cache, disabled both libraries and fbconnect and re-enabled, flushed cache again.

Retried this several times to no avail. Still get the undefined getUser() and status report shows Facebook SDK not found.

facebook.php and base_facebook.php reside in

/sites/all/libraries/facebook-php-sdk/src/

Can't seem to make any headway getting this fixed.

Libraries is the alpha version, btw.

cleaver’s picture

@cjs, I applied the patch in this thread and *not* the libraries module patch. I think the libraries patch (changing to index 0) was just a hack to work around this bug.

buhbuhbuhbowser’s picture

I'm having the problem too...not that that's unique. I'm wondering how the patch should be applied? Should I paste it into my libraries.module file?
My error is this: Call to a member function getLoginUrl() on a non-object in /home/content/84/8138184/html/sites/all/modules/fbconnect/fbconnect.pages.inc on line 231, but I'm assuming its just a manifestation of the same one. And when I go to the status page it says that facebook php sdk is not installed.

ofktoubro’s picture

Applying patches is
patch -b < filename.patch
Look here: http://www.brightlemon.com/blog/applying-patches-drupal or do a search for more...

ofktoubro’s picture

Patch in #27 applied to D7.10 with fbconnect 7.x-2.x-dev AND libraries 7.x-2.0-alpha2.
It now finds the fb library at sites/all/libraries/facebook-php-sdk
Tnx tstoeckler, JamesAn and cleaver

buhbuhbuhbowser’s picture

Patch in #27 worked, thank you all, and thanks ofktoubro for telling me how to patch. My sanity depends on people like you.
When I installed the libraries module, i stuck the folder inside sites/all/modules, but now when I put the facebook API i need to put it inside sites/all/libraries? I made a copy of the libraries module, but this just confuses me a bit.

cleaver’s picture

Status: Needs work » Needs review

If this is working for people, please review and set status to RTBC.

NVaissaud’s picture

I confirm #33.

I applied the patch #27 and *not* the libraries module patch (keep version of libraries alpha2 to 1) and it finally works.

tstoeckler’s picture

Also note that currently the dev release is exactly the same as alpha2 so it really is basically impossible that that is the cause of any problems. Libraries API also has tests and such, but as of now, there isn't a byte of difference...

juggernautsei’s picture

Hi,

I am new here and trying to follow the flow of the conversation. I applied the patch to my new drupal install of 7.12 and my code is reading this in the fbconnect.module:

function fbconnect_libraries_info() {
// Returns an associative array, with information about external library
$libraries['facebook-php-sdk'] = array(
'name' => 'Facebook PHP SDK',
'vendor url' => 'https://github.com/facebook/php-sdk',
'download url' => 'https://github.com/facebook/php-sdk/tarball/v3.1.1',
'version arguments' => array(
'file' => 'readme.md',
// Best practice: Document the actual version strings for later reference.
// 3.1.1: Facebook PHP SDK (v.3.1.1), filters for 3.x.x versions
'pattern' => '/Facebook PHP SDK \(v\.(3\.\d\.\d)\)/',
'lines' => 10,
),
// supported library version, including relevant files
'versions' => array(
'v.3.1.1' => array(
'files' => array(
'php' => array(
'src/base_facebook.php',
'src/facebook.php',
),
),
),
),
);
return $libraries;

Is this correct?

I am still getting this:

Fbconnect 7.x-2.x-dev Allows users to connect with Facebook account
Requires: Libraries (missing)
Required by: Facebook Friends Invite (disabled), FBConnect Test (disabled)

Thanks for any help.

Sherwin

tstoeckler’s picture

'versions' => array(
'v.3.1.1' => array(
'files' => array(

needs to be

'versions' => array(
'3.1.1' => array(
'files' => array(

Btw, I'm now officially unsubscribing from this issue. If there is any further problem with Libraries API please open a new issue in the queue there.

jcisio’s picture

Status: Needs review » Reviewed & tested by the community

RTBC #27

jcisio’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.