Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4483936
  • 博文数量: 356
  • 博客积分: 10458
  • 博客等级: 上将
  • 技术积分: 4734
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-24 14:59
文章分类

全部博文(356)

文章存档

2020年(17)

2019年(9)

2018年(26)

2017年(5)

2016年(11)

2015年(20)

2014年(2)

2013年(17)

2012年(15)

2011年(4)

2010年(7)

2009年(14)

2008年(209)

分类: C/C++

2012-06-30 13:55:04

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,比如
打开这个url, 点击其中的授权按钮,得到mini-frob比如 308-936-510,这个是有时限的

申请的api_key 与secret在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

建立~/.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

非基于网站式的
c930289a47042177api_key414b612d9e45cea5164dccb6a26ac861frob72157630007720051-32e737f131739e3b-968122permswrite 取md5值后生成api_sig
其组成格式是[secret]api_key[api_key]frob[frob]perms[perms] ,其取md5后形成api_sig

以上链接交给用户,经用户同意授权后,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 是为了解决交叉编译的一个问题,其内容如下:

点击(此处)折叠或打开

  1. --- configure 2011-12-29 08:03:28.000000000 +0800
  2. +++ configure.new 2012-05-14 10:17:26.000000000 +0800
  3. @@ -12711,12 +12711,12 @@
  4. if test $ac_cv_func_vsnprintf = yes; then
  5. { $as_echo "$as_me:${as_lineno-$LINENO}: checking vsnprintf has C99 compatible return value" >&5
  6. $as_echo_n "checking vsnprintf has C99 compatible return value... " >&6; }
  7. - if test "$cross_compiling" = yes; then :
  8. - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
  9. -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
  10. -as_fn_error $? "cannot run test program while cross compiling
  11. -See \`config.log' for more details" "$LINENO" 5; }
  12. -else
  13. +# if test "$cross_compiling" = yes; then :
  14. +# { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
  15. +#$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
  16. +#as_fn_error $? "cannot run test program while cross compiling
  17. +#See \`config.log' for more details" "$LINENO" 5; }
  18. +#else
  19. cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  20. /* end confdefs.h. */
  21. #include
  22. @@ -12747,7 +12747,7 @@
  23. fi
  24. rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
  25. conftest.$ac_objext conftest.beam conftest.$ac_ext
  26. -fi
  27. +#fi

  28. fi


阅读(4084) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~