Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I try to build OAuth authentication in the FlickrAPI module using this code sample: https://gist.github.com/1065774
After authenticating (all seems to work) I get the following PHP notice:
Notice: Use of undefined constant OAUTH_COMMON_TOKEN_TYPE_REQUEST - assumed 'OAUTH_COMMON_TOKEN_TYPE_REQUEST' in DrupalDatabaseCache->prepareItem() (line 428 of /includes/cache.inc).
Any idea what could cause this and how I can solve it? Thanks!
Comment | File | Size | Author |
---|---|---|---|
#8 | flickrapi-undefined-constant-on-cache-1515450-8.patch | 5.09 KB | juampynr |
Comments
Comment #1
BarisW CreditAttribution: BarisW commentedAnd I get this message also:
Any thoughts?
Comment #2
BarisW CreditAttribution: BarisW commentedI debugged a bit more and found out that it might be caused by the variables declaration in class DrupalOAuthToken:
if I change this to
All works fine. Can a static be used like this?
Comment #3
BarisW CreditAttribution: BarisW commentedWhat started as a support request actually is a bug report.
Comment #4
BarisW CreditAttribution: BarisW commentedSteps to reproduce:
- Install FlickrAPI 7.x-1.3
- Go to admin/config/media/flickrapi, fill in Flickr keys and click Authenticate. If you don't have a key and secret contact me and I will send you mine.
- Authenticate to Flickr using OAuth (happens when you save the admin form).
You'll see the notice.
I spoke to juampy on IRC and this was what he said:
All help here is welcome!
Comment #5
juampynr CreditAttribution: juampynr commentedThis is a weird one. Basically, some OAuth classes are getting registered at cache_bootstrap table under lookup_cache cid. These classes are being loaded before oauth_common.module, hence the error.
I need to discover at what point does this happens and how to avoid it. For that, I will trace a full OAuth authentication process to see what is going on on each step.
Here is an example of my cache_bootstrap table after authenticating. See how these classes got registered. These classes are loaded very early in the bootstrap process.
Comment #6
BarisW CreditAttribution: BarisW commentedDid you happen to do this yet? It really is an annoying issue, as all sites that rely on the FlickrAPi module (and submodules like FlickrGallery) will see this error/notice once they use the OAuth authentication.
Is there anything I can do in my module to work around this?
Comment #7
juampynr CreditAttribution: juampynr commentedI worked on it yesterday and I am not certain of what is going on yet. I was actually reading at how Flickrapi module creates the request token. It seems that info about class DrupalOAuthClient is saved in lookup_cache at drupal_goto() (which saves the user session to database). Twitter module, for example, uses OAuth as well but does not have this problem.
I will work on this a little bit more and hopefully find a fix in OAuth or a patch for Flickrapi.
Comment #8
juampynr CreditAttribution: juampynr commentedMoved to Flickrapi module.
The problem comes because the full DrupalOAuthToken object returned from Flickr was being saved using variable_set(). Then drupal_goto() provokes that saved variables get stored at cache_bootstrap table, which finally raises an error for every following page because when this variable is loaded, the class DrupalOAuthToken has not being loaded yet.
I have removed this object from being saved an created a private callback to check if a Flickr account has been authenticated instead.
Please review the suggested patch and consider Git Attribution.
Comment #9
BarisW CreditAttribution: BarisW commentedAwesome Juan! Thanks a lot for the research and the patch.
Committed, with git attribution (of course).