注意: 新浪微博需要提供回调地址才行
回调地址去新浪开发者平台获取
[ShareSDK connectSinaWeiboWithAppKey:@"3819780424" appSecret:@"6ce8dba1a8baa6803b6e3824518422b3" redirectUri:@"http://www.baidu.com"];
redirectUri 要和开发平台的回调页面相同
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [ShareSDK registerApp:@"288fe15ac67e"]; //参数为ShareSDK官网中添加应用后得到的AppKey //Parse Key [Parse setApplicationId:@"gKROXKemyAYT1JEQPwFjcuNRL7qPLguXpYWS1qb9" clientKey:@"U48G8pla1trx8voPeOpH8Hts9QN475g27STuxuWo"]; ///新浪微博: //App Key:3819780424 //App Secret:6ce8dba1a8baa6803b6e3824518422b3 //腾讯微博: //App key:2620460989 //App secret:58c55f572d5ae35e0c355f4c0ee11283 //分享内容URL [ShareSDK connectSinaWeiboWithAppKey:@"3819780424" appSecret:@"6ce8dba1a8baa6803b6e3824518422b3" redirectUri:@"http://www.baidu.com"]; // //新浪微博 // //App Key:801498670 // //App Secret:882c5581fa08e4068e9b920b65dac4ac // // //添加腾讯微博应用 // [ShareSDK connectTencentWeiboWithAppKey:@"801307650" // appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c" // redirectUri:@"http://www.sharesdk.cn"]; // //添加豆瓣应用 // [ShareSDK connectDoubanWithAppKey:@"07d08fbfc1210e931771af3f43632bb9" // appSecret:@"e32896161e72be91" // redirectUri:@"http://dev.kumoway.com/braininference/infos.php"]; // // //添加人人网应用 // [ShareSDK connectRenRenWithAppKey:@"fc5b8aed373c4c27a05b712acba0f8c3" // appSecret:@"f29df781abdd4f49beca5a2194676ca4"]; // // // // //添加Facebook应用 // [ShareSDK connectFacebookWithAppKey:@"107704292745179" // appSecret:@"38053202e1a5fe26c80c753071f0b573"]; return YES; }
其中传入ShareSDK的参数则是之前创建应用的AppKey,而Parse的ApplicationId和clientKey可在应用信息面板中获取。
//(新浪微博)例:在AppDelegate添加2个方法: - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [ShareSDK handleOpenURL:url wxDelegate:nil]; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:nil]; }
打开*-Info.plist(*代表你的工程名字)。找到URL types配置项(如果没有则新增),展开URL types – URL Schemes,在URL Schemes下分别各新增一项用于新浪微博的Scheme(如果不添加则会导致法返回应用)。其填写格式为:wb+appKey(你在新浪微博申请的AppKey), 如:wb2279784657。如图所示:
- (void)logoutButtonClickHandler:(id)sender { [ShareSDK cancelAuthWithType:ShareTypeSinaWeibo]; [self.navigationController popViewControllerAnimated:NO]; }
作者: 清澈Saup