当前位置: 首页 > 工具软件 > Flickcurl > 使用案例 >

c实现的Flickr API库Flickcurl介绍

乐正烨熠
2023-12-01
api介绍
http://www.flickr.com/services/api/

Flickcurl: C library for the Flickr API
http://librdf.org/flickcurl/

Register application to get API Key and Shared Secret
http://librdf.org/flickcurl/api/flickcurl-auth-register.html

Getting Authentication Token from API Key and Secret
http://librdf.org/flickcurl/api/flickcurl-auth-authenticate.html

请根据上面url进行操作,其大致步骤是注册并申请app key后会给出类似以下信息
test flickr
key:
414b612d9e45cea5164dccb6a26ac861
密鑰:
c930289a47042177
得到一个 認證 URL,比如 http://www.flickr.com/auth-72157629676228252
打开这个url, 点击其中的授权按钮,得到mini-frob比如 308-936-510,这个是有时限的

申请的api_key 与secret在http://www.flickr.com/services/api/keys/中可查询到
认证url的获取方式:
If you ever need to alter or view the authentication, use the link 'Edit the authentication flow' on right-hand side of the application page.
All your Flickr applications are linked from http://www.flickr.com/services/apps/by/me

建立~/.flickcurl.conf内容如下,root用户则为/.flickcurl.conf
[flickr]
api_key=414b612d9e45cea5164dccb6a26ac861
secret=c930289a47042177

下载flickcurl源码并 编译flickcurl后,执行
flickcurl -a 308-936-510
会自动更新 ~/.flickcurl.conf文件
如果成功返回如下信息
flickcurl: Successfully exchanged frob 308-936-510 for authentication token
flickcurl: Updated configuration file /home/zengming/.flickcurl.conf with authentication token

官网上还介绍了其他的认证方式:
基于网站式的权限认证
c930289a47042177api_key414b612d9e45cea5164dccb6a26ac861permswrite 取md5值后生成api_sig
http://www.flickr.com/services/auth/?api_key=414b612d9e45cea5164dccb6a26ac861&perms=write&api_sig=fb2ad09656b01151f66ceee2d25cd49d
非基于网站式的
c930289a47042177api_key414b612d9e45cea5164dccb6a26ac861frob72157630007720051-32e737f131739e3b-968122permswrite 取md5值后生成api_sig
其组成格式是[secret]api_key[api_key]frob[frob]perms[perms] ,其取md5后形成api_sig
http://www.flickr.com/services/auth/?api_key=414b612d9e45cea5164dccb6a26ac861&perms=write&frob=72157630007720051-32e737f131739e3b-968122&api_sig=d4488582bdf975f3f1b57ce47d89c8fd
以上链接交给用户,经用户同意授权后,frob才会有效,这样再由frob生成token

有了 token 后,就可以做很多事了(注意这个token有时效性的,似乎是24小时失效)
比如
Return a list of Flickr supported blogging services
./flickcurl blogs.getServices
0) blog service: id beta.blogger.com  name 'Blogger'
1) blog service: id LiveJournal  name 'LiveJournal'
2) blog service: id MetaWeblogAPI  name 'Wordpress'
3) blog service: id BloggerAPI  name 'BloggerAPI'
4) blog service: id Twitter  name 'Twitter'

flickr.galleries.getList
Return the list of galleries created by a user. Sorted from newest to oldest.

people.findByEmail           EMAIL
      get a user's NSID from their EMAIL address

people.findByUsername        USERNAME
      get a user's NSID from their USERNAME

./flickcurl people.findByUsername "wo shi tian cai"
flickcurl: NSID 78325574@N06 for username wo shi tian cai
user_id 似乎与NSID是一样的

上传图片
flickcur --help
    upload                       FILE [PARAMS...]
      Upload a photo FILE with optional parameters PARAM or PARAM VALUE
        title TITLE
        description DESC
        safety_level 'safe' (default) or 'moderate' or 'restricted'
        content_type 'photo' (default) or screenshot' or 'other'
        hidden 'public' (default) or 'hidden'
        friend
        public
        family
        tags TAGS... [must be last param]

./flickcurl upload /windows/F/pictures/2011052314541562312.jpg  title "test title" description "test description" public
flickcurl: Uploading file /windows/F/pictures/2011052314541562312.jpg
flickcurl: Photo upload status
  Photo ID: 7180353030

upload的实现参照flickcurl源码下utils/flickcurl.c
函数static int command_upload(flickcurl* fc, int argc, char *argv[])

how to cross compile
必须先编译出依赖的libxml2 与curl,然后再利用configure生成Makefile
tar -xvf flickcurl-1.22.tar.gz
cd flickcurl-1.22/
patch -p0 < ../flickcurl-1.22-cc.patch

下面说下交叉编译方法,普通的PC编译则会更简单
假设 libxml安装在
/home/zengming/workspace/googledata/flickr/libxml2-2.7.8/out
libcurl安装在/home/zengming/workspace/googledata/curl-7.21.1/out
ac_cv_func_malloc_0_nonnull=yes ./configure PKG_CONFIG_PATH=/home/zengming/workspace/googledata/flickr/libxml2-2.7.8/out/lib/pkgconfig:/home/zengming/workspace/googledata/curl-7.21.1/out/lib/pkgconfig CC=arm-linux-gcc --host=arm-linux
make
在 src/.libs/下会生成lib, 外部接口都声明在头文件 src/flickcurl.h中,其他程序要调用时,只要lib与这个头文件就够了
utils/.libs/下会生成测试程序flickcurl

加 ac_cv_func_malloc_0_nonnull=yes 是为了解决以下问题

flickr/flickcurl-1.22/utils/flickcurl.c:1215: undefined reference to `rpl_malloc'
作者:帅得不敢出门 C++哈哈堂<31843264>


./flickcurl-1.22-cc.patch 是为了解决交叉编译的一个问题,其内容如下:
--- configure   2011-12-29 08:03:28.000000000 +0800
+++ configure.new   2012-05-14 10:17:26.000000000 +0800
@@ -12711,12 +12711,12 @@
 if test $ac_cv_func_vsnprintf = yes; then
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking vsnprintf has C99 compatible return value" >&5
 $as_echo_n "checking vsnprintf has C99 compatible return value... " >&6; }
-  if test "$cross_compiling" = yes; then :
-  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot run test program while cross compiling
-See \`config.log' for more details" "$LINENO" 5; }
-else
+#  if test "$cross_compiling" = yes; then :
+#  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+#$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+#as_fn_error $? "cannot run test program while cross compiling
+#See \`config.log' for more details" "$LINENO" 5; }
+#else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <stdarg.h>
@@ -12747,7 +12747,7 @@
 fi
 rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
   conftest.$ac_objext conftest.beam conftest.$ac_ext
-fi
+#fi
 
 fi
 
 类似资料: