sina demo 说明(官方文档demo)
来源:互联网 发布:北斗手机导航软件 编辑:程序博客网 时间:2024/06/06 17:47
1.如何让官方demo跑起来?
#define kAppKey @"your app_key"
#define kAppSecret @"your app_secret"
#define kAppRedirectURI @"your app_rederict_uri"
上面这三个东西一定要有,否则不行。
2.对于sso登陆,如何回到demo?
- 打开demo的Info.plist
- 将Info.plist中URL Schemes的sinaweibosso.xxxxx,(xxx换成你自己的appkey)
进阶:根据官方demo提取需要的功能,以分享网络图片为例
DEMO地址:http://download.csdn.net/detail/take8619702/4797035
1.sso登陆之后不能回到自己的程序?
需要重写AppDelegate中的两个方法为:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [self.sinaWeiBohandleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [self.sinaWeiBohandleOpenURL:url];
}
如果多个sdk都需要重写这两个方法,则根据url的类型调用不同的sdk中的handOpenURL
2.登陆成功后程序没有记录登陆信息,每次重新登陆?
初始化SinaWeiBo对象时需要赋值给对象,如下(官方demo):
NSUserDefaults *defaults = [NSUserDefaultsstandardUserDefaults];
NSDictionary *sinaweiboInfo = [defaultsobjectForKey:@"SinaWeiboAuthData"];
if ([sinaweiboInfo objectForKey:@"AccessTokenKey"] && [sinaweiboInfoobjectForKey:@"ExpirationDateKey"] &&
[sinaweiboInfo objectForKey:@"UserIDKey"]) {
_sinaWeiBo.accessToken = [sinaweiboInfoobjectForKey:@"AccessTokenKey"];
_sinaWeiBo.expirationDate = [sinaweiboInfoobjectForKey:@"ExpirationDateKey"];
_sinaWeiBo.userID = [sinaweiboInfoobjectForKey:@"UserIDKey"];
}
登陆成功后,要存下登陆信息
SinaWeibo *sinaweibo = [appDelegatesinaWeiBo];(appDelegate = (AppDelegate *)[[UIApplication shareApplication] delegate])
NSDictionary *authData = [NSDictionarydictionaryWithObjectsAndKeys:
sinaweibo.accessToken,@"AccessTokenKey",
sinaweibo.expirationDate,@"ExpirationDateKey",
sinaweibo.userID,@"UserIDKey",
sinaweibo.refreshToken,@"refresh_token", nil];
[[NSUserDefaults standardUserDefaults] setObject:authDataforKey:@"SinaWeiboAuthData"];
[[NSUserDefaults standardUserDefaults] synchronize];
登出微博,需要将这些信息清除[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"SinaWeiboAuthData"];
[[NSUserDefaults standardUserDefaults]synchronize];
3.分享一张网络图片,已知URL地址
SinaWeibo *sinaweibo = [appDelegatesinaWeiBo];
UIImage * tempImage = [UIImageimageWithData:[NSData dataWithContentsOfURL:[NSURLURLWithString:@"http://static.androidesk.com/download/5099c1050a2ae0706b7cbc38"]]];
[sinaweibo requestWithURL:@"statuses/upload.json"
params:[NSMutableDictionarydictionaryWithObjectsAndKeys:
@"sina new interface success maybe",@"status",
tempImage, @"pic",nil]
httpMethod:@"POST"
delegate:self];//delegate sinaweiborequestdelegate
4.如何知道分享状态,成功或者失败?实现SinaWeiboRequestDelegate代理,可以得到返回状态的request
官方方法:
- (void)request:(SinaWeiboRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError : %@", [errorlocalizedDescription]);
if ([request.urlhasSuffix:@"users/show.json"])
{
[userInfo release],userInfo = nil;
}
elseif ([request.urlhasSuffix:@"statuses/user_timeline.json"])
{
[statuses release],statuses = nil;
}
elseif ([request.urlhasSuffix:@"statuses/update.json"])
{
UIAlertView *alertView = [[UIAlertViewalloc] initWithTitle:@"Alert"
message:[NSString stringWithFormat:@"Post status failed!"]
delegate:nil cancelButtonTitle:nilotherButtonTitles:@"OK", nil];
[alertView show];
[alertView release];
NSLog(@"Post status failed with error : %@", error);
}
elseif ([request.urlhasSuffix:@"statuses/upload.json"])
{
UIAlertView *alertView = [[UIAlertViewalloc] initWithTitle:@"Alert"
message:[NSString stringWithFormat:@"Post image status failed! with error : %@", [errorlocalizedDescription]]
delegate:nil cancelButtonTitle:nilotherButtonTitles:@"OK", nil];
[alertView show];
[alertView release];
NSLog(@"Post image status failed with error : %@", error);
}
}
- (void)request:(SinaWeiboRequest *)request didFinishLoadingWithResult:(id)result
{
NSLog(@"didFinishLoadingWithResult :%@", request);
if ([request.urlhasSuffix:@"users/show.json"])
{
[userInfo release];
userInfo = [result retain];
}
elseif ([request.urlhasSuffix:@"statuses/user_timeline.json"])
{
[statuses release];
statuses = [[result objectForKey:@"statuses"] retain];
}
elseif ([request.urlhasSuffix:@"statuses/update.json"])
{
UIAlertView *alertView = [[UIAlertViewalloc] initWithTitle:@"Alert"
message:[NSString stringWithFormat:@"Post status \"%@\" succeed!", [resultobjectForKey:@"text"]]
delegate:nil cancelButtonTitle:nilotherButtonTitles:@"OK", nil];
[alertView show];
[alertView release];
}
elseif ([request.urlhasSuffix:@"statuses/upload.json"])
{
NSLog(@"Request ---> : %@", result);
//发送微博成功
UIAlertView *alertView = [[UIAlertViewalloc] initWithTitle:@"Alert"
message:[NSString stringWithFormat:@"Post image status succeed!"]
delegate:nil cancelButtonTitle:nilotherButtonTitles:@"OK", nil];
[alertView show];
[alertView release];
}
}
- sina demo 说明(官方文档demo)
- 关于sina微博官方Demo使用问题说明
- asi官方文档及demo
- 小程序官方文档demo
- ActiveMQ 官方demo (p2p)
- 【Android开发】Android跨进程通讯(AIDL)官方文档及官方Demo讲解
- android 拍摄视频的简单demo(来自google官方文档)
- 微信小程序联盟:官方文档+精品教程+demo集合(11月更新……)
- 微信小程序导航:官方文档+精品教程+demo集合(6月12日更新)
- 微信小程序联盟:官方文档+精品教程+demo集合(6月30日更新)
- 十月微信小程序导航:官方文档+精品教程+demo集合(10月14日更新)
- bootstrap日期插件官方文档与demo案例
- 浅谈android官方文档中自定义view的demo
- AddressBook UI 官方demo (IOS)
- Vuforia AR 官方DEMO研究(IOS)
- 达尔文OP2官方demo解读(一)
- WS-Security官方 demo
- mxgraph-官方demo(1)
- iOS核心系统编程最佳实践:绘图
- BitmapFactory decodeResource and decodeStream 's problem
- iOS核心系统编程最佳实践:动画
- JAVA_OPTS参数说明与配置
- Android杂谈--打开文件的Intent及使用
- sina demo 说明(官方文档demo)
- iOS核心系统编程最佳实践:视频
- 脚本防止重复执行
- zoj 3132 DNA Consensus String(字符串处理)
- iOS核心系统编程最佳实践:音频
- LINUX TCP编程
- 图像处理中MFC中unhandle exception 0xc0000005:access violation出错原因
- iOS核心系统编程最佳实践:沙盒
- 创建Windows Phone 7的试用版程序 简单实现方案(翻译)