微博项目 02集成 微博 sdk

5.集成 微博 sdk 

1)注册开发者帐号——创建应用———获取 appkey 遇到以下问题,

新浪微博 2.4sdk 一闪而过

2)将weibosdk 导入项目中,在constant中定义宏 存放appkey等

#define sinaAppKey @"1845834473"

#define sinaAppSecre  @"211fcdf8e9dedbc2fb24b4e37c9e7a08"

#define sinaAppURL @"https://api.weibo.com/oauth2/default.html"

3)在 AppDeledata.h中设置全局变量 wbtoken,代理 WeiboSDKDelegate,WBHttpRequestDelegate> 并实现其协议

#import <UIKit/UIKit.h>
#import "WeiboSDK.h"
@class MainViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate,WeiboSDKDelegate,WBHttpRequestDelegate>
{
         
    NSString *wbtoken;
   // NSString *wbtoken;
}

@property (strong, nonatomic) UIWindow *window;
@property (nonatomic,retain) MainViewController *mainctrl;
@property (strong, nonatomic) NSString *wbtoken;
@property int reson;

@end

初始化 微博sdk

   [WeiboSDK enableDebugMode:YES];
    
    [WeiboSDK registerApp:sinaAppKey];

 

 

 

 

实现协议  - (void)didReceiveWeiboRequest:(WBBaseRequest *)request和  - (void)didReceiveWeiboResponse:(WBBaseResponse *)response

#pragma mark - Authorize Request/Response
- (void)didReceiveWeiboRequest:(WBBaseRequest *)request
{
    
}
- (void)didReceiveWeiboResponse:(WBBaseResponse *)response
{
    
    NSLog(@"成功了");
    self.wbtoken = [(WBAuthorizeResponse *)response accessToken];
    reson=(int)response.statusCode;
    
    //expirationDate
    NSDictionary *authData = [NSDictionary dictionaryWithObjectsAndKeys:
                             self.wbtoken, @"AccessTokenKey",
                        [(WBAuthorizeResponse *)response expirationDate], @"ExpirationDateKey",
                             [(WBAuthorizeResponse *)response userID], @"UserIDKey",nil];
    [[NSUserDefaults standardUserDefaults] setObject:authData forKey:@"SinaWeiboAuthData"];
    [[NSUserDefaults standardUserDefaults] synchronize];

   
    

}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [WeiboSDK handleOpenURL:url delegate:self];; } @end



 

posted @ 2014-10-31 13:25  尐苹果  阅读(221)  评论(0编辑  收藏  举报