Mobypicture Photo post with API method php

Image representing Mobypicture as depicted in ...

Image via CrunchBase

include(/*‘api.php’);
$mp = new Mobypicture;
$result = $mp->postMediaUrl(‘imagename,’username‘, ‘password‘);
$result = $mp->postMedia();
print_r($result);

 

====================================================
API .php
===============================================================
<?php

/**
* A Mobypicture API class
*
* @author Andreas Creten/madewithlove
* @version 1
**/
class Mobypicture {
/**
* The MobyPicture API key
**/
static $api_key = ‘zkFcHG1hpSqL4Xb2’;

/**
* The MobyPicture API Location
**/
static $api_location = ‘https://api.mobypicture.com/&#8217;;

/**
* Upload media to MobyPicture
*
* @param string $image The image to be uploaded
* @param string $username The username of the uploader
* @param string $password The p
* @param string $description
* @param array $tags  Tags for the image
* @param string $location
* @param array $hashtags
* @param array $services
* @return mixed
* @author Andreas Creten
**/
public function postMedia($image, $username, $password, $title = null, $description = null, $tags = array(), $location = null, $hashtags = array(), $services = array()) {
// Call the postMedia method on thw MobyPicture API
$response = $this->api_call(‘postMedia’, array(
‘i’ => $image,
‘u’ => $username,
‘p’ => $password,
‘t’ => $title,
‘d’ => $description,
‘tags’ => implode(‘,’, $tags),
‘latlong’ => $location,
‘ht’=> implode(‘,’, $hashtags),
‘s’ => implode(‘,’, $services)
));

// Parse the response of the MobyPicture API
if($response->result) {
print_r();
if(isset($response->result[‘code’]) && $response->result[‘code’] == 0) {
return $response;
}
else {
// This needs more detailed error messages
return false;
}
}
}

/**
* Upload media to MobyPicture
*
* @param string $image The image to be uploaded
* @param string $username The username of the uploader
* @param string $password The password of the uploader
* @param array $tags Tags for the image
* @return mixed
* @author Andreas Creten
**/
public function postMediaUrl($image, $username, $password) {

// Call the postMedia method on thw MobyPicture API
$response = $this->api_call(‘postMediaUrl’, array(
‘i’ => $image,
‘u’ => $username,
‘p’ => $password
//’tags’ => implode(‘,’, $tags)
));

print_r($tags);
exit;
// Parse the response of the MobyPicture API
if($response->result) {

if(isset($response->result[‘code’]) && $response->result[‘code’] == 0) {
return $response;
}
else {
// This needs more detailed error messages
return false;
}
}
}

/**
* Get the thumbnail url for an image on MobyPicture
*
* @param string $tinyurl The tinyurl or tinyurl code for of picture
* @param string $size The size of the needed thumbnail (thumbnail, small or medium)
* @return mixed
* @author Andreas Creten
* @todo
**/
public function getThumb($tinyurl, $size = ‘thumbnail’) {
// Try to remove the crap out of the tiny url
$tinyurl_code = $this->tinyurl_to_tinyurl_code($tinyurl);

// Call the getThumbUrl method on thw MobyPicture API
$response = $this->api_call(‘getThumbUrl’, array(
‘t’ => $tinyurl,
‘s’ => $size
));

// Parse the response of the MobyPicture API
if($response->result) {
if(isset($response->result[‘code’]) && $response->result[‘code’] == 0) {
return $response;
}
else {
// This needs more detailed error messages
return false;
}
}
}

/**
* Get the thumbnail url for an image on MobyPicture
*
* @param string $tinyurl The tinyurl or tinyurl code for of picture
* @param string $size The size of the needed thumbnail (thumbnail, small or medium)
* @return mixed
* @author Andreas Creten
**/
public function getThumbUrl($tinyurl, $size = ‘thumbnail’) {
// Try to remove the crap out of the tiny url
$tinyurl_code = $this->tinyurl_to_tinyurl_code($tinyurl);

// Call the getThumbUrl method on thw MobyPicture API
$response = $this->api_call(‘getThumbUrl’, array(
‘t’ => $tinyurl,
‘s’ => $size
));

// Parse the response of the MobyPicture API
if($response->result) {
if(isset($response->result[‘code’]) && $response->result[‘code’] == 0) {
return $response;
}
else {
// This needs more detailed error messages
return false;
}
}
}

/**
* Get the info of an image on MobyPicture
*
* @param string $tinyurl The tinyurl or tinyurl code for of picture
* @return mixed
* @author Andreas Creten
**/
public function getMediaInfo($tinyurl) {
// Try to remove the crap out of the tiny url
$tinyurl_code = $this->tinyurl_to_tinyurl_code($tinyurl);

// Call the getThumbUrl method on thw MobyPicture API
$response = $this->api_call(‘getMediaInfo’, array(
‘t’ => $tinyurl
));

// Parse the response of the MobyPicture API
if($response->result) {
if(isset($response->result[‘code’]) && $response->result[‘code’] == 0) {
return $response;
}
else {
// This needs more detailed error messages
return false;
}
}
}

/**
* Check an account on MobyPicture
*
* @param string $username
* @param string $pin The password of the user
* @return mixed
* @author Andreas Creten
**/
public function checkCredentials($username, $pin) {
// Call the createUser method on the MobyPicture API
$response = $this->api_call(‘checkCredentials’, array(
‘u’ => $username,
‘p’ => $pin
));

// Parse the response of the MobyPicture API
if($response->result) {
//log_r($response);
if(isset($response->result[‘code’]) && $response->result[‘code’] == 0) {
return true;
}
else {

return $response;
}
}
}

/**
* Post a comment on MobyPicture
*
* @param string $username Username (can be a Twitter username)
* @param string $pin PIN or password
* @param string $name Name (not used in case an username has been supplied)
* @param string $email Email (not used in case an username has been supplied)
* @param string $tinyurl The tinyurl or tinyurl code for of picture
* @param string $message
* @param string $tweet Tweets this comment on Twitter if possible with the supplied credentials
* @return mixed
* @author Andreas Creten
**/
public function postComment($username, $pin, $name, $email, $tinyurl, $message, $tweet = 0) {
// Try to remove the crap out of the tiny url
$tinyurl_code = $this->tinyurl_to_tinyurl_code($tinyurl);

// Call the createUser method on thw MobyPicture API
$response = $this->api_call(‘postComment’, array(
‘u’ => $username,
‘p’ => $pin,
‘name’ => $name,
’email’ => $email,
‘tinyurl_code’ => $tinyurl_code,
‘message’ => $message,
‘tweet’ => $tweet
));

// Parse the response of the MobyPicture API
if($response->result) {
//log_r($response);
if(isset($response->result[‘code’]) && $response->result[‘code’] == 0) {
return true;
}
else {

return $response;
}
}
}

/**
* Create a new account on MobyPicture
*
* @param string $tinyurl The tinyurl or tinyurl code for of picture
* @return mixed
* @author Andreas Creten
**/
public function getComments($tinyurl) {
// Try to remove the crap out of the tiny url
$tinyurl_code = $this->tinyurl_to_tinyurl_code($tinyurl);

// Call the createUser method on thw MobyPicture API
$response = $this->api_call(‘getComments’, array(
‘tinyurl_code’ => $tinyurl_code
));

// Parse the response of the MobyPicture API
if($response->result) {
//log_r($response);
if(isset($response->result[‘code’]) && $response->result[‘code’] == 0) {
return true;
}
else {

return $response;
}
}
}

/**
* Create a new account on MobyPicture
*
* @param string $username
* @param string $pin The password for the new user
* @param string $email
* @param string $firstname
* @param string $lastname
* @param string $country
* @param string $keepposted
* @param string $agreeterms
* @return mixed
* @author Andreas Creten
**/
public function createUser($username, $pin, $email, $firstname, $lastname, $country, $keepposted, $agreeterms) {
// Call the createUser method on thw MobyPicture API
$response = $this->api_call(‘createUser’, array(
‘username’ => $username,
‘pin’ => $pin,
’email’ => $email,
‘firstname’ => $firstname,
‘lastname’ => $lastname,
‘countryid’ => $country,
‘keepposted’ => $keepposted,
‘agreeterms’ => $agreeterms
));

// Parse the response of the MobyPicture API
if($response->result) {
//log_r($response);
if(isset($response->result[‘code’]) && $response->result[‘code’] == 0) {
return true;
}
else {

return $response;
}
}
}

/**
* Search posts on MobyPicture
*
* @param string $terms Specifies for which words to search
* @param string $items_per_page Amount of posts to show on each page (default: 10)
* @param string $current_page The current page (default: 1)
* @param string $fields  Specifies in what fields to search (‘title’, ‘description’ or ‘both’, default: both)
* @param array $tags Look for one or more tags
* @param string $username Only return postings from the specified username
* @param string $sort_by Sort the results based on this field
* @param string $order Specifies in which direction sorting should be done
* @param string $country Only return postings from the specified country (ISO3166 code2)
* @param string $city Only return postings from the specified city
* @return mixed
* @author Andreas Creten
**/
public function searchPosts($terms, $items_per_page = 10, $current_page = 1, $fields = ‘both’, $tags = array(), $username = null, $sort_by = null, $order = null, $country = null, $city = null) {
// Call the createUser method on thw MobyPicture API
$response = $this->api_call(‘searchPosts’, array(
‘searchTerms’ => $terms,
‘searchItemsPerPage’ => $items_per_page,
‘searchPage’ => $current_page,
‘searchIn’ => $fields,
‘searchUsername’ => $lastname,
‘searchTags’ => implode(‘,’, $tags),
‘searchSortBy’ => $sort_by,
‘searchOrder’ => $order,
‘searchGeoCity’ => $city,
‘searchGeoCountry’ => $country
));

// Parse the response of the MobyPicture API
if($response->result) {
//log_r($response);
if(isset($response->result[‘code’]) && $response->result[‘code’] == 0) {
return true;
}
else {

return $response;
}
}
}

/**
* Do a call to the MobyPicture API
*
* @param string $method The method to be called
* @param array $arguments The arguments for this call
* @return SimpleXMLObject The MobyPicture response
* @author Andreas Creten
**/
private function api_call($method, $arguments) {

// Check which type of method it is (postMedia requers another type of handling)
if($method == ‘postMedia’) {
// Initialize the curl session
$ch = curl_init();

// Set the target url
curl_setopt($ch, CURLOPT_URL, self::$api_location);

// Enable post
curl_setopt($ch, CURLOPT_POST, 1);

// Enable return transfer
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// Create the arguments array
$arguments = array_merge($arguments, array(
‘k’      => self::$api_key,
‘action’ => $method,
‘format’ => ‘xml’
));

// Load the image file
$arguments[‘i’] = ‘@’.$arguments[‘i’] ;

// Add the arguments to curl
curl_setopt($ch, CURLOPT_POSTFIELDS, $arguments);

// Execute the curl request
$result = curl_exec($ch);

// Close curl
curl_close($ch);

print_r($result);

// Return the response as an SimpleXML object
return simplexml_load_string($result);
}
else {
// Compose the target URL
$url = sprintf(self::$api_location.’?action=%s&k=%s&format=xml&%s’, $method, self::$api_key, http_build_query($arguments));

// Return the response as an SimpleXML object
return simplexml_load_file($url);
}
}

/**
* Transform a Mobypicture tinyurl into a tinyurl_code
*
* @param string $tinyurl The tinyurl for the picture
* @return string The tinyurl code for the picture
* @author Andreas Creten
**/
private function tinyurl_to_tinyurl_code($tinyurl) {
// Try to remove the crap out of the tiny url
$tinyurl = str_replace(‘http://mobypicture.com/?&#8217;, ”, $tinyurl);
$tinyurl = str_replace(‘http://www.mobypicture.com/?&#8217;, ”, $tinyurl);
$tinyurl = str_replace(‘http://moby.to/&#8217;, ”, $tinyurl);

return $tinyurl;
}
}

?>

  1. Anonymous
    March 30, 2012 at 11:43 PM

    Hello there, You have performed a fantastic job. I’ll certainly digg it and in my opinion recommend to my friends. I’m sure they’ll be benefited from this web site.

  2. April 24, 2012 at 6:12 AM

    Hey There. I discovered your weblog the use of msn. This is a really neatly written article. I will be sure to bookmark it and come back to learn more of your useful info. Thank you for the post. I will certainly comeback.

  3. April 7, 2013 at 3:54 AM

    Hello There. I found your blog the usage of msn. That is a really well written article.
    I will be sure to bookmark it and come back to read extra of your helpful information.
    Thank you for the post. I will definitely return.

  4. April 9, 2013 at 2:09 AM

    If you desire to improve your familiarity only keep visiting
    this web page and be updated with the latest gossip posted here.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: