【问题标题】:How to get new Access Token in Box api after it getting expire过期后如何在 Box api 中获取新的访问令牌
【发布时间】:2014-10-09 22:47:03
【问题描述】:

以下是 Box Api 教程中给出的获取新访问令牌的过程。

卷曲https://www.box.com/api/oauth2/token

-d 'grant_type=refresh_token&refresh_token={有效刷新令牌}&client_id= {your_client_id}&client_secret={your_client_secret}'

-X 发布

这是我的代码

 NSString* refresh =[NSString stringWithFormat:@"{%@}",[[arrUseraccounts objectAtIndex:[BoxDownloadFileViewControlller getSharedInstance].index] objectForKey:@"refresh_token"]];

    NSString* clientId =[NSString stringWithFormat:@"{%@}",[BoxSDK sharedSDK].OAuth2Session.clientID];
    NSString* clientSecret =[NSString stringWithFormat:@"{%@}", [BoxSDK sharedSDK].OAuth2Session.clientSecret];

   // NSDictionary * dic = [NSDictionary dictionaryWithObject:refresh forKey:@"refresh_token"];

    ASIFormDataRequest *postParams = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"https://www.box.com/api/oauth2/token?"]];
    //
    //    ASIFormDataRequest *postParams = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://www.box.com/api/oauth2/token?grant_type=refresh_token&refresh_token=%@&client_id=%@&client_secret=%@",refresh,clientId,clientSecret]]];

        [postParams setRequestMethod:@"POST"];

    //[postParams setPostBody:data];
    [postParams setPostValue:@"refresh_token" forKey:@"grant_type"];
    [postParams setPostValue:refresh forKey:@"refresh_token"];
    [postParams setPostValue:clientId forKey:@"client_id"];
    [postParams setPostValue:clientSecret forKey:@"client_secret"];

    [postParams startAsynchronous];
    postParams.delegate = self ;
    postParams.userInfo = [NSDictionary dictionaryWithObject:@"accessToken" forKey:@"id"];

    NSLog(@"Url is ---> %@",postParams.url);
    NSLog(@"response string is-----> %@",postParams.responseString);

我遇到了以下问题。

{"error":"invalid_client","error_description":"The client credentials are invalid"}

请建议 mne 如何传递 Box Api 教程中给出的参数。

【问题讨论】:

    标签: ios access-token box


    【解决方案1】:

    我得到了解决方案。

    NSString* refresh =your refresh token;
    
    NSString* clientId =[NSString stringWithFormat:@"%@",[BoxSDK sharedSDK].OAuth2Session.clientID];
    NSString* clientSecret =[NSString stringWithFormat:@"%@", [BoxSDK sharedSDK].OAuth2Session.clientSecret];
    
    ASIFormDataRequest *postParams = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"https://www.box.com/api/oauth2/token?"]];
    
    [postParams setRequestMethod:@"POST"];
    
    [postParams setPostValue:@"refresh_token" forKey:@"grant_type"];
    [postParams setPostValue:refresh forKey:@"refresh_token"];
    [postParams setPostValue:clientId forKey:@"client_id"];
    [postParams setPostValue:clientSecret forKey:@"client_secret"];
    
    [postParams startAsynchronous];
    postParams.delegate = self ;
    postParams.userInfo = [NSDictionary dictionaryWithObject:@"accessToken" forKey:@"id"];
    
    NSLog(@"Url is ---> %@",postParams.url);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      • 2021-08-25
      • 2013-01-09
      • 2018-06-05
      相关资源
      最近更新 更多