进入到九月,新浪微博把Auth1的接口关闭了,导致以前分享微博的功能失效了。
在ShareKit中增加Auth2.0新浪微博的分享的方法如下:
1、添加一个新的文件夹,Sina Weibo V2(类似于Sina Weibo ,略有不同)
2、在OAAsynchronousDataFetcher.m文件里面添加下面的方法。因为OAuth2.0不需要通过HMAC-SHA1 生成 signature
- (void)startNoPrepare { // [request prepare]; if (connection) [connection release]; connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; if (connection) { if (responseData) [responseData release]; responseData = [[NSMutableData data] retain]; } else { OAServiceTicket *ticket= [[OAServiceTicket alloc] initWithRequest:request response:nil didSucceed:NO]; [delegate performSelector:didFailSelector withObject:ticket withObject:nil]; [ticket release]; } }
3、在ShreKitDemoConfigurator.m里添加如下内容
- (NSString*)sinaWeiboV2ConsumerKey { return @"XXXXX"; } - (NSString*)sinaWeiboV2ConsumerSecret { return @"XXXXX"; } // You need to set this if using OAuth (MUST be set, it could be any words) - (NSString*)sinaWeiboV2CallbackUrl { return @"https://api.weibo.com/oauth2/default.htm"; }
4、在DefaultSHKConfigurator.m添加如下内容
- (NSString*)sinaWeiboV2ConsumerKey { return @""; } - (NSString*)sinaWeiboV2ConsumerSecret { return @""; } // You need to set this if using OAuth (MUST be set, it could be any words) - (NSString*)sinaWeiboV2CallbackUrl { return @""; }
5、更改SHKSharers.plist里面的文件,完成即可。
6、注意事项
之前在iOS里面分享新浪微博的时候总是看到两种界面,如下截图
主要是授权链接的问题,给出链接的URLString
NSString* urlStr1 = [NSStringstringWithFormat:@"%@?client_id=%@&response_type=code&redirect_uri=%@&display=mobile", authorizeURL, self.consumerKey, [self.authorizeCallbackURL.absoluteStringURLEncodedString]];
NSString* urlStr2 = [NSString stringWithFormat:@"%@?client_id=%@&response_type=code&redirect_uri=%@", authorizeURL, self.consumerKey, [self.authorizeCallbackURL.absoluteString URLEncodedString]];
链接的差别就是多了一个&display=mobile,虽然两个都可用,但是针对web的和针对mobile的还是不一样的
第一种方式用户体验更加好。仅供参考。