Originally published at: http://www.sitepoint.com/commenting-upvoting-uploading-photos-500px-api/
Building a Custom 500px Laravel App
- Popular Photos, Filters and User Profiles with the 500px API
- Commenting, Upvoting and Uploading Photos with the 500px API
In the first part of this series we used the API to get the latest photos from 500px and filter through them, and we built a user profile with the list of associated photos. In this part, we are going to give the user the ability to vote, favorite and comment on photos, and finally, we will give the users the ability to upload their own photos. Let’s get started.
Authorization
When trying to access an API endpoint we need to check the authentication level required to access the resource. The API may require a consumer_key
or an OAuth.
In the first part we registered a new application on 500px and received our consumer_key
and consumer_secret
. We use the Grant app to get a valid token
and token_secret
for testing.
Authentication
After specifying your consumer_key
and consumer_secret
, you receive a token
and a token_secret
. These are going to give you the right to post and retrieve user content.
// bootstrap/start.php
App::singleton('pxoauth', function(){
$host = 'https://api.500px.com/v1/';
$consumer_key = 'YOUR CONSUMER KEY';
$consumer_secret = 'YOUR CONSUMER SECRET';
$token = 'GRANT TOKEN';
$token_secret = 'GRANT TOKEN SECRET';
$oauth = new PxOAuth($host, $consumer_key, $consumer_secret, $token, $token_secret);
return $oauth;
});
The PxOAuth
class wraps our communication with the 500px API.