1 / 8

FLICKR PHP

FLICKR PHP. ETHEL D COFIE www.ethelcofie.com. Preparation. 1. Obtain an API key 2.Configure your key- Shared Secret Link : http://www.flickr.com/services/api/keys/. Use both keys to construct login url. If you're not using an API kit, then construct the url as follows:

osborn
Download Presentation

FLICKR PHP

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Preparation • 1. Obtain an API key • 2.Configure your key-Shared Secret Link : http://www.flickr.com/services/api/keys/

  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_key=[api_key]&perms=[perms]&api_sig=[api_sig] PHP $secret_key=’1234567889’; $params = array(‘api_key’=> ‘123456676,‘perms’ => ‘write’); $encoded_param = array(); foreach($params as $key => $value){$encoded_params[] = urlencode($key).’=’.urlencode($value);} $apisig=md5($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); –>This 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_serialparamater serial to retrieve the format in serialized data structure$frobparams = array(‘api_key’=> ‘api_key’,‘frob’ => ‘frob’ ,‘method’ => ‘flickr.auth.getToken’,‘format’ => ‘php_serial’); $encoded_param = array(); foreach($frobparams as $key => $value){$encoded_params[] = urlencode($key).’=’.urlencode($value);}$url = “http://api.flickr.com/services/rest/?”.implode(’&’, $encoded_params);

  5. Create an auth handler(Part 2 ) Get url response/contents$rsp = file_get_contents($url); $rsp_obj = unserialize($rsp); $details=$rsp_obj; Glean Auth Token from $details if($details[stat]==’ok’){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_decode($data['api_key']).'auth_token'.base64_url_decode($data['auth_token'])); // the parameters $encoded_params = array(); //$encoded_params['title']=$data['title']; $encoded_params['api_key'] = base64_url_decode($data['api_key']); $encoded_params['api_sig'] = $data['api_sig']; $encoded_params['auth_token'] = base64_url_decode($data['auth_token']); $encoded_params['photo'] = "@".$_FILES['photo']['tmp_name']; curl_setopt($ch, CURLOPT_POSTFIELDS,$encoded_params); //other stuff curl_setopt($ch,CURLOPT_RETURNTRANSFER ,1); $result= curl_exec($ch); curl_close($ch); return $result; }

  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; $out=false; for($i=0 ; $i<count($vals); $i++) { while(($vals[$i]['attributes']['STAT']== 'ok') && $out==false) { $status_check = true; $out=true;// 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['primary_photo_id']=$findphoto['value']; //use to get photo link } }

More Related