iOS 框架,用于操作 my.mail.ru (мой мир@mail.ru) REST API。您可以使用它进行此社交网络和所有其他 API 方法的认证。有关 REST API 方法的详细信息,请查阅 此处。
将以下框架链接到您的项目
将 MyMailRuSDK 目录中的所有源文件拖放到您的项目中(不需要 MyMailRuSDK.xcodeproj)。
另一种方法是使用 zip 文件已编译的框架。
MyMailRu SDK 需要 iOS 5+ 并使用 ARC 构建。
应用启动时的配置
[MyMailRu setAppId:@"123456"];
[MyMailRu setAppPrivateKey:@"1q2345ereygennvfe"];
使用缓存令牌打开会话(无需用户交互)
[MMRSession openSessionWithPermissions:@[@"stream"] // or any others permissions that your app need
loginBehavior:MMRSessionLoginWithCachedToken
completionsHandler:^(UIViewController *authViewController, MMRSession *session, NSError *error) {
if (!error) {
NSLog(@"Session silent open successfully");
} else {
NSLog(@"%@", error);
}
}];
使用您应用程序中的授权控制器打开会话
[MMRSession openSessionWithPermissions:[self applicationPermissions]
loginBehavior:MMRSessionLoginWithAuthorizationController
completionsHandler:^(UIViewController *authViewController, MMRSession *session, NSError *error) {
if (authViewController) {
[self presentViewController:authViewController
animated:YES
completion:nil];
return;
}
NSString *result = nil;
if (error) {
result = [error localizedDescription];
} else {
result = @"Success";
}
NSLog(@"%@", result);
}];
}
使用用户名和密码打开会话
if (![MMRSession currentSession].isValid) {
[MMRSession openSessionForUsername:@"[email protected]"
password:@"123qwe456"
permissions:@[@"stream"]
completionsHandler:^(MMRSession *session, NSError *error) {
NSString *result = nil;
if (error) {
result = [error localizedDescription];
} else {
result = @"Success";
}
NSLog(@"%@", result);
}];
}
获取当前用户信息
MMRRequest *request = [MMRRequest requestForUsersInfoWithParams:@{@"uids" : [MMRSession currentSession].userId}];
[request sendWithCompletionHandler:^(id json, NSError *error) {
NSString *result = nil;
if (error) {
result = [error localizedDescription];
} else {
result = [NSString stringWithFormat:@"%@", json];
}
NSLog(@"%@", result);
}];
向用户的流发送帖子
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"user_text"] = [NSString stringWithFormat:@"We are testing MyMailRu SDK for iOS now :)"];
params[@"link1_text"] = @"kittens";
params[@"link1_href"] = @"http://placekitten.com/200/300";
params[@"img_url"] = @"http://placekitten.com/200/300";
params[@"text"] = @"Here goes some kittens";
params[@"title"] = @"Post from MyMailRu SDK";
MMRRequest *request = [MMRRequest requestForStreamPostWithParams:params];
[request sendWithCompletionHandler:^(id json, NSError *error) {
NSString *result = nil;
if (error) {
result = [error localizedDescription];
} else {
result = [NSString stringWithFormat:@"%@", json];
}
];
MyMailRuSDK for iOS 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE
文件。