Skip this Video
Download Presentation
Integrating with Services

Loading in 2 Seconds...

play fullscreen
1 / 18

Integrating with Services - PowerPoint PPT Presentation

  • Uploaded on

Integrating with Services. Up to this point, we’ve focused on reading from external sources… Writing: Get better functionality than you can write Flickr, google maps, &c Get access to better (more?) audience Facebook, Tumblr, &c Lots of business examples. Business Examples.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about ' Integrating with Services' - hagop

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
integrating with services
Integrating with Services
  • Up to this point, we’ve focused on reading from external sources…
  • Writing:
    • Get better functionality than you can write
      • Flickr, google maps, &c
    • Get access to better (more?) audience
      • Facebook, Tumblr, &c
      • Lots of business examples
business examples
Business Examples
  • Nike pedometer -> fb thing
  • Others…..
  • Pass username/password of end user
    • What’s bad about this idea?
  • One time (session) key
  • Permanent service-to-service key
    • User creates a key at the 3rd party service which it shares with both the local and remote service.
tumblr post i
Tumblr: Post I

// Authorization info

$tumblr_email = \'[email protected]\';

$tumblr_password = \'secret\';

// Data for new record

$post_type = \'regular\';

$post_title = \'The post title\';

$post_body = \'This is the body of the post.\';

// Prepare POST request

$request_data = http_build_query( array( \'email\' => $tumblr_email, \'password\' => $tumblr_password, \'type\' => $post_type, \'title\' => $post_title, \'body\' => $post_body, \'generator\' => \'API example\' ) );

tumblr post ii
Tumblr: Post II

// Send the POST request (with cURL) $c = curl_init(\'\');

curl_setopt($c, CURLOPT_POST, true);

curl_setopt($c, CURLOPT_POSTFIELDS, $request_data);

curl_setopt($c, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($c);

$status = curl_getinfo($c, CURLINFO_HTTP_CODE);


// Check for success

if ($status == 201)

{ echo "Success! The new post ID is $result.\n"; }

else if ($status == 403) { echo \'Bad email or password\'; } else { echo "Error: $result\n"; }

tumblr api
Tumblr API

flickr example auth
Flickr Example: Auth

Our web based app has the api key \'1234567890\'. It has already registered a callback url for this key - \'\'.

  • User visits and clicks on the \'login\' link.
  • This link points to
  • The user is already logged in to flickr - they are asked if they wish to allow the application to have \'read\' permissions to their photos.
  • The user clicks \'yes\' and flickr updates it\'s auth database.
  • The user is redirected to
  • The app makes a background call to flickr.auth.getToken:
  • The call returns an auth token \'334455\'.
  • The application stores the auth token and creates a session for the user with a cookie which points to the user\'s auth token.
  • The application makes a background request to the flickr.people.getInfo to return information about the user, by calling
flickr upload
Flickr: Upload


  • Arguments
    • photo The file to upload.
    • title (optional) The title of the photo.
    • Description (optional) A description of the photo. May contain some limited HTML.
    • tags (optional) A space-seperated list of tags to apply to the photo.
    • is_public, is_friend, is_family (optional) Set to 0 for no, 1 for yes. Specifies who can view the photo.
    • safety_level (optional) Set to 1 for Safe, 2 for Moderate, or 3 for Restricted.
    • content_type (optional) Set to 1 for Photo, 2 for Screenshot, or 3 for Other.
    • hidden (optional) Set to 1 to keep the photo in global search results, 2 to hide from public searches.
flickr documentation
Flickr Documentation
  • Auth:
  • Upload:
  • PHP library:
good apis are complex
Good APIs are complex
  • Let libraries do some of the work
  • Google/Blogger Example:

require_once \'Zend/Loader.php\'; Zend_Loader::loadClass(\'Zend_Gdata\'); Zend_Loader::loadClass(\'Zend_Gdata_Query\'); Zend_Loader::loadClass(\'Zend_Gdata_ClientLogin\');

more google w library
More Google w/ Library
  • Auth

$user = \'[email protected]\'; $pass = \'secretPasswd\'; $service = \'blogger\';

$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service, null, Zend_Gdata_ClientLogin::DEFAULT_SOURCE, null, null, Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, \'GOOGLE\');

$gdClient = new Zend_Gdata($client);

more google w library1
More Google w/ Library
  • Post

function createPublishedPost($title=\'Hello, world!\', $content=\'I am blogging on the internet.\') {

$uri = \'\' . $blogID . \'/posts/default\';

$entry = $gdClient->newEntry();

$entry->title = $gdClient->newTitle($title);

$entry->content = $gdClient->newContent($content);


$createdPost = $gdClient->insertEntry($entry, $uri);

$idText = split(\'-\', $createdPost->id->text); $newPostID = $idText[2]; return



google api library
Google API + Library
  • Write a service that relies on another for visible persistence
  • Write a PHP that
    • Take a path to an image on the web
      • By a get request: myscript.php?img=http://www…
    • Overlays the word ‘FAIL’ on it
    • Saves it locally
    • FTPs it to your (public) RSC space
    • Returns (prints) the URL of the file in your rpi space
    • Check out ex 1
  • Before the lab
    • Set up a Tumblr account
  • During Lab
    • Edit today’s in class work such that every time you post an image, it creates a tumblr post, including your edited image


$homepage = file_get_contents(\'http://…...’);

file_put_contents("index.html", $homepage);

$file = \'index.html\';

$remote_file = \'public_html/index.html\';

// set up basic connection

$conn_id = ftp_connect(\'\');

// login with username and password

$login_result = ftp_login($conn_id, ‘########\', ‘###########\');

// upload a file

if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {

echo "successfully uploaded $file\n";

} else {

echo "There was a problem while uploading $file\n";


// close the connection