iphone 里使用sharekit实现分享信息到facebook、twitter

    因为项目里要用到这方面的功能,最近一直在研究怎么实现。还好运气不错,找到一个工具sharekit,

可以很方便的把信息分享到facebook和twitter上面。

    ShareKit 是iPhone中一键分享文字,图片,链接,文件到Facebook, twitter, delicious, tumblr, google reader等第三方网站的objc库 
(1) Download : http://getsharekit.com/d/ShareKit.0.2.1.zip 
(2) Github : http://github.com/ideashower/sharekit/ 


详细配置如下:

一.首先需要在SHKConfig.h中针对应用的名称和回调链接作一个全局设置:


#define SHKMyAppName            @"iWhat" //app的名称
#define SHKMyAppURL             @"http://itunes.apple.com/cn/app/id388833522?mt=8"  //itunes上的链接

二.第三方平台的OAUTH配置(即获得相应的API Key和API Secret)


1.Facebook

<1>.创建一个application(http://www.facebook.com/developers/ 
<2>.将上面生成的key对应到SHKConfig.h: 


#define SHKFacebookUseSessionProxy        NO
#define SHKFacebookKey                    @"e5aeb908d24f4c7ace1a623374280869"
#define SHKFacebookSecret                 @"b09478d7873bd4779f387c3e58f9df93"
#define SHKFacebookSessionProxyURL        @"" // left it blank here

2.Twitter

<1>.创建一个基于browser的application (http://dev.twitter.com/apps/new) 
<2>.将上面生成的key对应到SHKConfig.h: 

#define SHKTwitterConsumerKey        @"oUYTCJTaB1BmQnIBDKPMTg"
#define SHKTwitterSecret             @"U4CDOvOTvUnEfHuEUfrvphQ96UFZYv87R6q7ZG1jsM"
#define SHKTwitterCallbackUrl        @"http://itunes.apple.com/cn/app/id388833522?mt=8"
#define SHKTwitterUseXAuth           0 // To use xAuth, set to 1
#define SHKTwitterUsername           @""  // left it blank here , if use xAuth

注意:如果使用oauth,SHKTwitterCallbackUrl这一项目一定要填,url是不是真实存在都可以,但是要和twitter上创建的应用
里的callbackurl相对应。

三.相关调用代码

- (void)loadToolbar
{
   UIBarButtonItem *spaceItem = [[[UIBarButtonItem alloc]
                                  initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                  target:self
                                  action:nil] autorelease];            
   
   UIBarButtonItem *shareItem = [[[UIBarButtonItem alloc]                
                                 initWithBarButtonSystemItem:UIBarButtonSystemItemAction  
                                 target:self  
                               action:@selector(shareLink)] autorelease];
   
   CGRect rect = CGRectMake(0,392, 320, 44);
   UIToolbar *toobar = [[[UIToolbar alloc] initWithFrame:rect] autorelease];
   toobar.barStyle = UIBarStyleBlackOpaque;    
   toobar.items = [[NSArray alloc] initWithObjects:spaceItem,shareItem,spaceItem,nil];
   [self.view addSubview:toobar];    
}


- (void)shareLink
{
   NSURL *sharedURL = [NSURL URLWithString:@"http://www.google.com"];
   SHKItem *item = [SHKItem URL:sharedURL title:@"Google Test"];
   SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
   [actionSheet showFromToolbar:self.navigationController.toolbar];
}

四.注意: 
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) 


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值