Skip to content

Instantly share code, notes, and snippets.

@yyjim
Created November 3, 2011 08:09
Show Gist options
  • Save yyjim/1336020 to your computer and use it in GitHub Desktop.
Save yyjim/1336020 to your computer and use it in GitHub Desktop.
Mixi revoke and Mixi setup
// in Mixi.m
/*
is there a way can check revoke successful?
i can not find where return kMixiAppApiTypeRevoke value in
- (NSString*)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation error:(NSError**)error
but in README said we can check it.
*/
NSError *error = nil;
NSString *apiType = [[Mixi sharedMixi] application:application openURL:url sourceApplication:sourceApplication annotation:annotation error:&error];
if (error) {
  // エラーが発生しました
}
else if ([apiType isEqualToString:kMixiAppApiTypeToken]) {
  // 認可処理に成功しました
}
else if ([apiType isEqualToString:kMixiAppApiTypeRevoke]) {
  // 認可解除処理に成功しました
}
- (NSString*)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation error:(NSError**)error
{
if ([[url path] isEqualToString:@"/error"]) {
if (error != nil) {
*error = [self retrieveErrorFromURL:url];
}
}
else if ([[url path] isEqualToString:@"/cancel"]) {
if (error != nil) {
*error = [NSError errorWithDomain:kMixiErrorDomain
code:kMixiCancelled
userInfo:[NSDictionary dictionaryWithObject:@"Your request cancelled." forKey:@"message"]];
}
}
else if ([[url host] isEqualToString:@"token"]) {
UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:self.config.pbkey create:NO];
if (pasteboard == nil) {
if (error != nil) {
*error = [NSError errorWithDomain:kMixiErrorDomain
code:kMixiTokenErrorCannotRetrieve
userInfo:[NSDictionary dictionaryWithObject:@"Any token cannot be retrieved." forKey:@"message"]];
}
}
else {
url = (NSURL*)[pasteboard valueForPasteboardType:@"public.url"];
[self retrieveTokensFromURL:url sourceApplication:sourceApplication error:error];
if (error == nil || *error == nil) {
[self store];
}
}
return kMixiAppApiTypeToken;
}
else if ([[url host] isEqualToString:@"run"] && [[url query] hasPrefix:@"mixi_request_id="]) {
return kMixiAppApiTypeReceiveRequest;
}
return [url host];
}
// here is setup Mixi singleton code
_mixi = [[Mixi sharedMixi] setupWithType:kMixiApiTypeSelectorGraphApi
clientId:[[self class] appKey]
secret:[[self class] appSecret]
appId:[[self class] appId]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment