Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Refresh the token that i got from google oauth 2.0 in iOS
    primarykey
    data
    text
    <p>I am making an iOS application that uses the user's google account to get data from his youtube account and show them .... first step is done using the gtm2 to authenticate the user and get an acces-token and a refresh-token the problem is that the access-token expires after 60 minutes and i have to login and allow the application again... i have found that you can use the refresh-token to get a new access-token using this from the documetation : --> my question is how to make a POST request to get the access token in objective-c this is the data i need to use:</p> <pre><code>POST /o/oauth2/token HTTP/1.1 Host: accounts.google.com Content-Type: application/x-www-form-urlencoded client_id=21302922996.apps.googleusercontent.com&amp; client_secret=XTHhXh1SlUNgvyWGwDk1EjXB&amp; refresh_token=1/6BMfW9j53gdGImsixUH6kU5RsR4zwI9lUVX-tqf8JXQ&amp; grant_type=refresh_token </code></pre> <p>this is the code i am using :</p> <pre><code>NSString *post =[[NSString alloc] initWithFormat:@"client_secret=%@&amp;grant_type=refresh_token&amp;refresh_token=%@&amp;client_id%@",kGoogleClientSecretKey,kRefreshToken,kGoogleClientIDKey]; NSLog(@"%@",post); NSURL *url=[NSURL URLWithString:@"https://accounts.google.com/o/oauth2/token"]; NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ; [request setURL:url]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; NSError *error; NSURLResponse *response; NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error]; NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; NSLog(@"%@",data); </code></pre> <p>the error i get is : { "error" : "invalid_request" }</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload