ios - GitHub API撤销访问 token

标签 ios objective-c oauth access-token github-api

我已经通过使用GitHub API3将github成功集成到了我的ios App中。

但我的问题是我无法删除/撤消访问 token 。

我尝试了以下代码

NSString * querystr= @"https://api.github.com/authorizations";    

// i tried this url url also https://api.github.com/authorizations?client_id=1234yyrhrh

NSMutableURLRequest *request2 = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:querystr]];

[NSURLConnection sendAsynchronousRequest:request2 queue:theQ
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) 
{
      NSArray * array = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
      NSLog(@"%@",array);
}];

我没有收到任何错误,但是数组正在打印以下消息
"documentation_url" = "http://developer.github.com/v3";
 message = "Not Found";

提前致谢

最佳答案

终于我解决了。 。 。 :)

   NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.github.com/applications/%@/tokens/%@",GITHUB_CLIENT_ID,token]];

   NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
   NSString *theUsername = GITHUB_CLIENT_ID;
   NSString *thePassword = GITHUB_CLIENT_SECRET;

   [request addValue:[NSString stringWithFormat:@"Basic %@",[self base64forData:[[NSString stringWithFormat:@"%@:%@",theUsername,thePassword] dataUsingEncoding: NSUTF8StringEncoding]]] forHTTPHeaderField:@"Authorization"];
   [request setHTTPMethod:@"DELETE"];
   [request setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];

   NSError *error = nil;
   NSURLResponse *response;

   [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];



- (NSString*)base64forData:(NSData*)theData
{
    const uint8_t* input = (const uint8_t*)[theData bytes];
    NSInteger length = [theData length];

    static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

    NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
    uint8_t* output = (uint8_t*)data.mutableBytes;

    NSInteger i;
    for (i=0; i < length; i += 3) {
        NSInteger value = 0;
        NSInteger j;
        for (j = i; j < (i + 3); j++) {
            value <<= 8;

            if (j < length) {
                value |= (0xFF & input[j]);
            }
        }

        NSInteger theIndex = (i / 3) * 4;
        output[theIndex + 0] =                    table[(value >> 18) & 0x3F];
        output[theIndex + 1] =                    table[(value >> 12) & 0x3F];
        output[theIndex + 2] = (i + 1) < length ? table[(value >> 6)  & 0x3F] : '=';
        output[theIndex + 3] = (i + 2) < length ? table[(value >> 0)  & 0x3F] : '=';
    }

    return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];
}

关于ios - GitHub API撤销访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20489009/

相关文章:

testing - 当单击 iframe 中的提交链接 <a tag> 然后重定向到 OAUTH 流时,TestCafe 始终失败

ios - OAuth2 登录 SoundCloud 最近返回 Error Domain=NXOAuth2HTTPErrorDomain Code=401 "HTTP Error: 401"

ios - 发送推送时iOS角标(Badge)不会增加

ios - 此应用程序的 XCode 项目类型? OpenGL ES 还是基于 View ?

ios - 从另一个 View Controller 调用位于 Facebook sdk 上的函数

objective-c - 后台应用程序监听音频输入

c - 懂Objective-C的C难学吗

ios - 单击自定义 uitableviewcell 中的一个 uibutton 会选择 uitableview 中的多个 uibutton

PHP 网站 - Twitter API + Abraham Oauth(无法找到 x_rate_limit_remaining )

ios - Swift - 同时设置角半径和阴影