之前写的一个脚本已经可以成功获得auth token,有了它,你就可以与flickr进行通讯了。可以利用它给的API做你想做的事了。

我先实现了用API与设置的blog通讯的脚本,用这个脚本就可以给你选定的blog发文了,我分别测试了wordpress和twitter,都可以正常发文:

percy@o-2rl2:~/flickr$ cat blog.sh
#########################################################################
# Author: pengjianqing@gmail.com
# Created Time: Mon 03 Aug 2009 07:48:46 PM CST
# File Name: blog.sh
# Description:
#########################################################################
#!/bin/bash

API_KEY=***********************************
API_SECRET=********************************
#echo "API_KEY=${API_KEY}"
#echo "API_SECRET=${API_SECRET}"


echo "*********************************************************"
echo "Get auth token..."
echo "*********************************************************"
TOKEN=`cat token.xml|grep -i token|cut -d ">" -f2|cut -d "<" -f1`
echo TOKEN=${TOKEN}
echo "*********************************************************"
echo "Now you can use this token to Communication with flickr.com"
echo "Here I just get the info and the blog list I have setted in the flickr."
echo "*********************************************************"


echo "*********************************************************"
echo "Get blog list..."
echo "*********************************************************"
METHORD=flickr.blogs.getList
SIG=${API_SECRET}api_key${API_KEY}auth_token${TOKEN}method${METHORD}
echo SIG=${SIG}
API_SIG=`java md5 ${SIG}`
echo API_SIG=${API_SIG}
FLICKR_URL="http://flickr.com/services/rest/?method=${METHORD}&api_key=${API_KEY}&auth_token=${TOKEN}&api_sig=${API_SIG}"

wget  ${FLICKR_URL} -O bloglist.xml
cat bloglist.xml


echo "*********************************************************"
echo "Get Services list..."
echo "*********************************************************"
METHORD=flickr.blogs.getServices
SIG=${API_SECRET}api_key${API_KEY}auth_token${TOKEN}method${METHORD}
echo SIG=${SIG}
API_SIG=`java md5 ${SIG}`
echo API_SIG=${API_SIG}
FLICKR_URL="http://flickr.com/services/rest/?method=${METHORD}&api_key=${API_KEY}&auth_token=${TOKEN}&api_sig=${API_SIG}"

wget  ${FLICKR_URL} -O services.xml
cat services.xml

echo "*********************************************************"
echo "Sent a post to blog..."
echo "*********************************************************"
METHORD=flickr.blogs.postPhoto
PHOTO_ID=3783563309
echo "Please choose the blog you want to post a photo:"
BLOGS=`cat bloglist.xml |grep id|cut -d "=" -f3|sed 's/"//g'|sed 's/service//g'|grep -n ""`
echo "${BLOGS}"
read -p "Enter your choice:" CHOOSE
BLOGNAME=`echo "${BLOGS}"|grep "^${CHOOSE}"|cut -d ":" -f2`
echo BLOGNAME=${BLOGNAME}
BLOG_ID=`grep ${BLOGNAME} bloglist.xml|cut -d "\"" -f2`

read -p "Enter the password:" PASSWORD
read -p "Enter the Title:" TITLE
read -p "Enter the Description:" DESCRIPTION
#PASSWORD=""
echo PASSWORD=${PASSWORD}

SIG=${API_SECRET}api_key${API_KEY}auth_token${TOKEN}blog_id${BLOG_ID}blog_password${PASSWORD}description${DESCRIPTION}method${METHORD}photo_id${PHOTO_ID}title${TITLE}
echo SIG=${SIG}
API_SIG=`java md5 ${SIG}`
echo API_SIG=${API_SIG}
#FLICKR_URL="http://api.flickr.com/services/rest/?method=${METHORD}&api_key=${API_KEY}&blog_id=${BLOG_ID}&photo_id=${PHOTO_ID}&title=${TITLE}&description=${DESCRIPTION}&blog_password=${PASSWORD}&auth_token=${TOKEN}&api_sig=${API_SIG}"
FLICKR_URL="http://api.flickr.com/services/rest/?method=${METHORD}&api_key=${API_KEY}&blog_id=${BLOG_ID}&photo_id=${PHOTO_ID}&title=${TITLE}&description=${DESCRIPTION}&blog_password=${PASSWORD}&auth_token=${TOKEN}&api_sig=${API_SIG}"
wget  ${FLICKR_URL} -O postblog.xml
cat postblog.xml


下面这个是用来获取联系人信息的脚本:


percy@o-2rl2:~/flickr$ cat contact.sh
#########################################################################
# Author: pengjianqing@gmail.com
# Created Time: Mon 03 Aug 2009 07:48:46 PM CST
# File Name: blog.sh
# Description:
#########################################################################
#!/bin/bash

API_KEY=*********************
API_SECRET=************************
#echo "API_KEY=${API_KEY}"
#echo "API_SECRET=${API_SECRET}"


echo "*********************************************************"
echo "Get auth token..."
echo "*********************************************************"
TOKEN=`cat token.xml|grep -i token|cut -d ">" -f2|cut -d "<" -f1`
echo TOKEN=${TOKEN}
echo "*********************************************************"
echo "Now you can use this token to Communication with flickr.com"
echo "Here I just get the info and the blog list I have setted in the flickr."
echo "*********************************************************"


echo "*********************************************************"
echo "Get contact list..."
echo "*********************************************************"
METHORD=flickr.contacts.getList
SIG=${API_SECRET}api_key${API_KEY}auth_token${TOKEN}method${METHORD}
echo SIG=${SIG}
API_SIG=`java md5 ${SIG}`
echo API_SIG=${API_SIG}
FLICKR_URL="http://flickr.com/services/rest/?method=${METHORD}&api_key=${API_KEY}&auth_token=${TOKEN}&api_sig=${API_SIG}"

wget  ${FLICKR_URL} -O contactlist.xml
cat contactlist.xml

echo "*********************************************************"
echo "Get getListRecentlyUploaded"
echo "*********************************************************"
METHORD=flickr.contacts.getListRecentlyUploaded
SIG=${API_SECRET}api_key${API_KEY}auth_token${TOKEN}method${METHORD}
echo SIG=${SIG}
API_SIG=`java md5 ${SIG}`
echo API_SIG=${API_SIG}
FLICKR_URL="http://flickr.com/services/rest/?method=${METHORD}&api_key=${API_KEY}&auth_token=${TOKEN}&api_sig=${API_SIG}"

wget  ${FLICKR_URL} -O contactuploaded.xml
cat contactuploaded.xml



echo "*********************************************************"
echo "Get flickr.contacts.getPublicList"
echo "*********************************************************"
USER_ID=`grep nsid token.xml |cut -d "\"" -f2`
#USER_ID=40112025%40N03
METHORD=flickr.contacts.getPublicList
SIG=${API_SECRET}api_key${API_KEY}auth_token${TOKEN}method${METHORD}user_id${USER_ID}
echo SIG=${SIG}
API_SIG=`java md5 ${SIG}`
echo API_SIG=${API_SIG}
FLICKR_URL="http://api.flickr.com/services/rest/?method=${METHORD}&api_key=${API_KEY}&user_id=40112025%40N03&auth_token=${TOKEN}&api_sig=${API_SIG}"

wget  ${FLICKR_URL} -O contactpubliclist.xml
cat contactpubliclist.xml


下面这个是获得commons的脚本,现在还不清楚这个东西是做什么的:

percy@o-2rl2:~/flickr$ cat commons.sh
#########################################################################
# Author: pengjianqing@gmail.com
# Created Time: Mon 03 Aug 2009 07:48:46 PM CST
# File Name: blog.sh
# Description:
#########################################################################
#!/bin/bash

API_KEY=********************************
API_SECRET=*****************************
#echo "API_KEY=${API_KEY}"
#echo "API_SECRET=${API_SECRET}"


echo "*********************************************************"
echo "Get auth token..."
echo "*********************************************************"
TOKEN=`cat token.xml|grep -i token|cut -d ">" -f2|cut -d "<" -f1`
echo TOKEN=${TOKEN}
echo "*********************************************************"
echo "Now you can use this token to Communication with flickr.com"
echo "Here I just get the info and the blog list I have setted in the flickr."
echo "*********************************************************"


echo "*********************************************************"
echo "Get blog list..."
echo "*********************************************************"
METHORD=flickr.commons.getInstitutions
SIG=${API_SECRET}api_key${API_KEY}auth_token${TOKEN}method${METHORD}
echo SIG=${SIG}
API_SIG=`java md5 ${SIG}`
echo API_SIG=${API_SIG}
FLICKR_URL="http://flickr.com/services/rest/?method=${METHORD}&api_key=${API_KEY}&auth_token=${TOKEN}&api_sig=${API_SIG}"

wget  ${FLICKR_URL} -O commons.xml
cat commons.xml


其它API的实现应该和上面这些都会比较类似的,等全部测试完后,再重新整理一下。

Flickr API测试脚本2:与博客通信

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.