FLICKR PHP - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

FLICKR PHP

Description:

... This will then redirect back to your call back url and include a frob value ... if ($_REQUEST['frob' ... frob' = frob' , method' = flickr.auth.getToken' ... – PowerPoint PPT presentation

Number of Views:61
Avg rating:3.0/5.0
Slides: 9
Provided by: rdfu
Category:
Tags: flickr | php | frob

less

Transcript and Presenter's Notes

Title: FLICKR PHP


1
FLICKR PHP
  • ETHEL D COFIE
  • www.ethelcofie.com

2
Preparation
  • 1. Obtain an API key
  • 2.Configure your key-Shared Secret

3
Use both keys to construct login url
  • If you're not using an API kit, then construct
    the url as follows
  • http//flickr.com/services/auth/?api_keyapi_key
    permspermsapi_sigapi_sig
  • PHP
  • secret_key1234567889
  • params array(api_keygt 123456676,perms
    gt write)
  • encoded_param array()
  • foreach(params as key gt value)encoded_para
    ms urlencode(key)..urlencode(value)
  • apisigmd5(secret_key.api_key.params'api_key
    '.perms.params'perms')
  • url http//flickr.com/services/auth/?.
  • implode(,encoded_params).api_sig.apisig
  • header(Location.url) gtThis will then
    redirect back to your call back url and include a
    frob value()
  • (api_sig is a signature of the other two
    parameters. Signatures are created using your
    secret and the other argumnents listed in
    alphabetical order, name then value.)

4
Create an auth handler(Part 1 )
  • When users follow your login url, they are
    directed to a page on flickr.com which asks them
    if they want to authorize your application
  • When the user accepts the request, they are sent
    back to the Callback URL you defined
  • PHP
  • if (_REQUEST'frob')//using php_serial
    paramater serial to retrieve the format in
    serialized data structurefrobparams
    array(api_keygt api_key,frob gt frob
    ,method gt flickr.auth.getToken,format gt
    php_serial)
  • encoded_param array()
  • foreach(frobparams as key gt value)encoded_
    params urlencode(key)..urlencode(value)
    url http//api.flickr.com/services/rest/?.i
    mplode(, encoded_params)

5
Create an auth handler(Part 2 )
  • Get url response/contentsrsp
    file_get_contents(url)
  • rsp_obj unserialize(rsp)
  • detailsrsp_obj
  • Glean Auth Token from details
  • if(detailsstatok)echo
    details'auth''token''_content'else
  • //display error message if there is a
    problemecho details message

6
Make an authenticated method call
  • function curlpost(data)
  • keys'1234567788555' // api key
  • url "http//api.flickr.com/services/upload/"
  • ch curl_init()
  • //print_r(data)
  • // set the target url
  • curl_setopt(ch,CURLOPT_URL,url)
  • curl_setopt(ch,CURLOPT_POST,1)
  • curl_setopt(ch,CURLOPT_HTTP_VERSION,'HTTP/1.1')
  • curl_setopt(ch,CURLOPT_HEADER,0)
  • curl_setopt (ch, CURLOPT_HTTPHEADER,
    Array("Content-Type multipart/form-data"))
  •  
  •  
  • data'api_sig'md5(keys.'api_key'.base64_url_de
    code(data'api_key').'auth_token'.base64_url_dec
    ode(data'auth_token'))
  • // the parameters
  • encoded_params array()
  • //encoded_params'title'data'title'
  • encoded_params'api_key' base64_url_decode(da
    ta'api_key')

7
Make an authenticated method call
  • Using function
  • upload_result curlpost(_REQUEST)
  • parse xml_parser_create() // reates a new XML
    parser and returns a resource handle referencing
    it to be used by the other XML functions.
  • xml_parse_into_struct(parse,upload_result,
    vals, index)// his function parses an XML file
    into 2 parallel array structures, one (index )
    containing pointers to the location of the
    appropriate values in the values array. These
    last two parameters must be passed by reference.
  • xml_parser_free(parse)
  • //foreach to find status
  • status_check
  • outfalse
  • for(i0 iltcount(vals) i)
  • while((valsi'attributes''STAT' 'ok')
    outfalse)
  • status_check true

  • outtrue// checks to make sure it exists while
    loop

8
Make an authenticated method call
  • //foreach to get photosetid to be used in url
  • photoid
  • if( status_check true)
  • foreach(vals as findphoto)
  • if(findphoto'tag''PHOTOID')
  • //
    print_r(findphoto)
  • photo_details'prim
    ary_photo_id'findphoto'value' //use to get
    photo link
  • Image upload sample
  • flickrbarcamp_at_yahoo.com
  • Ethel Flickr demo .To demonstrate use of flickr
    API at bar camp
Write a Comment
User Comments (0)
About PowerShow.com