Guest User

Untitled

a guest
Feb 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use Data::Dumper;
  7.  
  8. use DBI;
  9. use Flickr::API;
  10. use XML::LibXML;
  11.  
  12. use Compress::Zlib; # boggle
  13.  
  14. # flickr initialisation
  15. my $key = undef;
  16. my $secret = undef; # your key and secret here
  17.  
  18. my $api = new Flickr::API({'key' => $key, 'secret' => $secret});
  19.  
  20. my $auth_token = '' || get_auth_token(); # get_auth_token lifted from flickr-export
  21. my $nsid = ''; # put in your NSID here (eg '48600109393@N01')
  22.  
  23. ## THE ACTUAL TAGGING BIT IS HERE
  24.  
  25. my $photo_id = "310301300313";
  26.  
  27. my $rsp = get_flickr_data('flickr.photos.addTags',
  28. { 'photo_id' => $photo_id,
  29. 'tags' => '"tags go here", "and here"', });
  30.  
  31. ## and this is the auth cruft
  32.  
  33. sub get_auth_token {
  34. # The user wants to authenticate. There's really no nice way to handle this.
  35. # So we have to spit out a URL, then hang around or something until
  36. # the user hits enter, then exchange the frob for a token, then tell the user what
  37. # the token is and hope they care enough to stick it into .flickrrc so they
  38. # only have to go through this crap once.
  39.  
  40. # 1. get a frob
  41. my $frob = get_frob( $api );
  42.  
  43. # 2. get a url for the frob
  44. my $url = $api->request_auth_url('write', $frob);
  45.  
  46. # 3. tell the user what to do with it
  47. print "1. Enter the following URL into your browser\n\n",
  48. "$url\n\n",
  49. "2. Follow the instructions on the web page\n",
  50. "3. Hit <Enter> when finished.\n\n";
  51.  
  52. # 4. wait for enter.
  53. <STDIN>;
  54.  
  55. # 5. Get the token from the frob
  56. my $auth_token = get_token( $api, $frob );
  57. die "Failed to get authentication token!" unless defined $auth_token;
  58.  
  59. # 6. Tell the user what they won.
  60. print "Your authentication token for this application is\n\t\t", $auth_token, "\n";
  61. print "Edit this program and insert this at line 20\n";
  62.  
  63. exit 0;
  64. }
  65.  
  66. sub get_frob {
  67. my $api = shift;
  68.  
  69. my $res = $api->execute_method("flickr.auth.get_frob");
  70. return undef unless defined $res and $res->{success};
  71.  
  72. # FIXME: error checking, please. At least look for the node named 'frob'.
  73. return $res->{tree}->{children}->[1]->{children}->[0]->{content};
  74. }
  75.  
  76. sub get_token {
  77. my $api = shift;
  78. my $frob = shift;
  79.  
  80. my $res = $api->execute_method("flickr.auth.get_token",
  81. { 'frob' => $frob } );
  82. return undef unless defined $res and $res->{success};
  83.  
  84. # FIXME: error checking, please.
  85. return $res->{tree}->{children}->[1]->{children}->[1]->{children}->[0]->{content};
  86. }
Add Comment
Please, Sign In to add comment