Reputation: 10069
I'm trying to list the albums from a single user in imgur. As far as I've read in the API, information about albums can only be fetched using the authenticated API, which is quite a curious decision, because you can upload images and messages with the anonymous API but can't get public information like lists of albums.
Anyways, looks like the auth API uses OAuth. I've been trying to find a way of making it work, with no luck. On of the reasons is that my hosting does not offer the official PHP's oauth extension, so I need an external library.
Do you have any example of working with imgur and oauth?
Upvotes: 3
Views: 4793
Reputation: 51411
There are a few good pure-PHP OAuth options for you that are worth mentioning. In order to understand their good parts and bad parts, it'll be nesecary to understand how OAuth works. Let's review.
In this example, the Provider is Imgur, the Consumer is your code, and the User is the user.
When we hit step 9, the OAuth object in your code has all it needs to perform requests. The key, critical part is that the OAuth object must handle API requests itself so that it can properly sign the data being sent over the wire.
There are two good options for you to pick from, and some not-so-good. Let's review the good ones:
First is PEAR's HTTP_OAuth, which uses HTTP_Request2 as the underlying HTTP library. While it works fine, HTTP_OAuth_Consumer_Request acts as a gateway to the request object, but doesn't inherit from it. This means that you can't do everything to it that you can do to an HTTP_Request2. This can be annoying.
Second, there's Zend Framework's Zend_Oauth, which uses Zend_Http_Client as the underlying HTTP library. While it's part of the larger Zend Framework, the two components are largely independent and work well with other frameworks... or no framework. Unlike the PEAR library, Zend_Oauth_Consumer actually returns a class that derives from Zend_Http_Client. That's not to say it doesn't do it's own weird thing. Instead of asking you to stash away the token and secret in the session, it wants you to serialize a status token object instead, which contains the token and secret. It gets the job done, but it's just weird.
Ignoring the warts, both are fine options for you. They're both released under liberal open source licenses, so you won't have a problem bundling them with your code. *
In the not-so-good category, there's oauth-php. I didn't care working with the library, too many distractions and little things that irritated me about it. There's also PECL's oauth extension. While it uses CURL, it's impossible to get the CURL handle out of it to make your own sane requests. You've also mentioned that you don't have it installed, which is why it's in the not-so-good category.
As for interfacing with Imgur... it's just plain vanilla JSON. Throw around PHP's native json_encode
and json_decode
and you won't have a problem at all. The API documentation is pretty darned good.
* I am not a lawyer, you might want to consult one.
(Parts of this answer are copied verbatim from, as it happens, an incomplete Imgur API library I started writing. Unfortunately I did not implement anything about albums, otherwise I'd just link it. Once it did what I needed it to do, I stopped. Sorry.)
Upvotes: 7
Reputation: 2234
i dont know about Imgur. but some good links on oauth api and code.. oauth almost work same for all service..
http://oauth.net/core/1.0/ as i have less than 10 reputation , i can post u only 2 hyperlinks
Upvotes: 2