Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5406351
  • 博文数量: 763
  • 博客积分: 12108
  • 博客等级: 上将
  • 技术积分: 15717
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-28 21:21
个人简介

业精于勤,荒于嬉

文章分类

全部博文(763)

文章存档

2018年(6)

2017年(15)

2016年(2)

2015年(31)

2014年(14)

2013年(87)

2012年(75)

2011年(94)

2010年(190)

2009年(38)

2008年(183)

2007年(28)

分类: C/C++

2011-02-09 10:48:58

ShareKit 是iPhone中一键分享文字,图片,链接,文件到Facebook, twitter, delicious, tumblr, google reader等第三方网站的objc库
(1) Download :
(2) Github :

详细配置如下:

一.首先需要在SHKConfig.h中针对应用的名称和回调链接作一个全局设置:
Java代码 复制代码
  1. #define SHKMyAppName            @"iSports"  
  2. #define SHKMyAppURL             @""  


二.第三方平台API Key的配置

1.Facebook
<1>.创建一个application(http://www.facebook.com/developers/
<2>.将上面生成的key对应到SHKConfig.h:
Java代码 复制代码
  1. #define SHKFacebookUseSessionProxy        NO   
  2. #define SHKFacebookKey                    @"e5aeb908d24f4c7ace1a623374280869"  
  3. #define SHKFacebookSecret                 @"b09478d7873bd4779f387c3e58f9df93"  
  4. #define SHKFacebookSessionProxyURL        @"" // left it blank here  


2.Twitter
<1>.创建一个基于browser的application (http://dev.twitter.com/apps/new)
<2>.将上面生成的key对应到SHKConfig.h:
Java代码 复制代码
  1. #define SHKTwitterConsumerKey        @"oUYTCJTaB1BmQnIBDKPMTg"  
  2. #define SHKTwitterSecret             @"U4CDOvOTvUnEfHuEUfrvphQ96UFZYv87R6q7ZG1jsM"  
  3. #define SHKTwitterCallbackUrl        @""  
  4. #define SHKTwitterUseXAuth           0 // To use xAuth, set to 1   
  5. #define SHKTwitterUsername           @""  // left it blank here , if use xAuth  


3.Bit.ly (for shortening URLs on Twitter:
(1)注册Bit.lyAPI key: )
Java代码 复制代码
  1. #define SHKBitLyLogin                @"marshluca"  
  2. #define SHKBitLyKey                  @"R_0177fa6e25c72544cb72bc5ec3150b4d"  


4.Read it Later
(1).注册API Key:()
Java代码 复制代码
  1. #define SHKReadItLaterKey            @"7d1dbZ6dTdh6ay8d42Ac1a3V7dgbQe1a"  


5.Tumblr  (不需要配置API Key)

6.Google Reader (不需要配置API Key)


三.调用代码:

Java代码 复制代码
  1. - (void)loadToolbar   
  2. {   
  3.    UIBarButtonItem *spaceItem = [[[UIBarButtonItem alloc]   
  4.                                   initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace   
  5.                                   target:self   
  6.                                   action:nil] autorelease];               
  7.       
  8.    UIBarButtonItem *shareItem = [[[UIBarButtonItem alloc]                   
  9.                                  initWithBarButtonSystemItem:UIBarButtonSystemItemAction     
  10.                                  target:self     
  11.                                action:@selector(shareLink)] autorelease];   
  12.       
  13.    CGRect rect = CGRectMake(0,39232044);   
  14.    UIToolbar *toobar = [[[UIToolbar alloc] initWithFrame:rect] autorelease];   
  15.    toobar.barStyle = UIBarStyleBlackOpaque;       
  16.    toobar.items = [[NSArray alloc] initWithObjects:spaceItem,shareItem,spaceItem,nil];   
  17.    [self.view addSubview:toobar];       
  18. }   
  19.   
  20.   
  21. - (void)shareLink   
  22. {   
  23.    NSURL *sharedURL = [NSURL URLWithString:@""];   
  24.    SHKItem *item = [SHKItem URL:sharedURL title:@"Google Test"];   
  25.    SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];   
  26.    [actionSheet showFromToolbar:self.navigationController.toolbar];   
  27. }  




四.注意:
1.只有Facebook, Twitter采用的是OAuth Connect

2.如果采取的是TabBarViewController结构的话,需要为每一个Share View对应的RooViewController做如下设置:(官方文档中没有说明这一点)
(1)先引入:#import "SHK.h"
(2)在RootViewController初始化的地方加上:[SHK setRootViewController:self];

3.不同APP不能共享一个OAuth Connect Secret Key , 否则在twitter和facebook分享的时候出现客户端分享成功,但是却没有真正提交到第三方网站的假分享.(一个mobile app必须严格对应一个facebook, twitter app)


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