使用xcode for ios在linkedin中获取accessstoken的oauth

时间:2014-01-06 13:31:20

标签: ios xcode oauth linkedin access-token

我在服务器中收到错误,同时请求链接在:

中的accessstoken
  

oauth_problem = signature_invalid&安培; oauth_problem_advice = com.linkedin.security.auth.pub.LoginDeniedInvalidAuthTokenException%20while%20obtaining%20request%20token%20for%20%3APOST%26https%253A%252F%252Fapi.linkedin.com%252Fuas%252Foauth %252FaccessToken%26oauth_consumer_key%253Dma6wmdg1a0lb%2526oauth_nonce%253DVltw%2526oauth_signature_method%253DHMAC-SHA1%2526oauth_timestamp%253D1389012417%2526oauth_token%253D75 - f8855da6-48eb-4df3-b0ea-865b5176ee4a%2526oauth_verifier%253D90683%2526oauth_version%253D1.0%0AOAU%3Ama6wmdg1a0lb% 7C75 - f8855da6-48eb-4df3-b0ea-865b5176ee4a%7C%2A01%7C%2A01%3A1389012417%3Ac1EHNqTOB7N%2B5BLY7NF2fWG3s4U%3D


我已经按照https://developer.linkedin.com/oauth-test-console

中指定的格式设置了reqest

我将requset设置为:

  

NSMutableString * parameterString = [[NSMutableString   ALLOC] initWithFormat:@ “”];

[parameterString appendFormat:@"oauth_callback=%@", [oauthCallback urlencode]];
[parameterString appendFormat:@"&oauth_consumer_key=%@", [oauthConsumerKey urlencode]];
[parameterString appendFormat:@"&oauth_nonce=%@", [oauthNonce urlencode]];
[parameterString appendFormat:@"&oauth_signature_method=%@", [oauthSignatureMethod urlencode]];
[parameterString appendFormat:@"oauth_token=\"%@\"", oauth_token];
[parameterString appendFormat:@"&oauth_timestamp=%@", [oauth_timestamp urlencode]];
[parameterString appendFormat:@"&oauth_version=%@", [oauthVersion urlencode]];

NSString *signatureBaseString = [NSString stringWithFormat:@"%@&%@&%@", httpMethod, [baseURL urlencode], [parameterString urlencode]];

NSString *signingKey = [NSString stringWithFormat:@"%@&", [oauthConsumerSecret urlencode]];

NSString *oauthSignature = [self hmacsha1:signatureBaseString secret:signingKey];

NSMutableString *urlString = [[NSMutableString alloc]initWithFormat:@""];

[urlString appendFormat:@"%@", baseURL];

NSMutableString *authHeader = [[NSMutableString alloc]initWithFormat:@""];

[authHeader appendFormat:@"OAuth "];

[authHeader appendFormat:@"oauth_nonce=\"%@\",", [oauthNonce urlencode]];
[authHeader appendFormat:@"oauth_signature_method=\"%@\",", [oauthSignatureMethod urlencode]];
[authHeader appendFormat:@"oauth_timestamp=\"%@\",", [oauth_timestamp urlencode]];
[authHeader appendFormat:@"oauth_consumer_key=\"%@\",", [oauthConsumerKey urlencode]];
[authHeader appendFormat:@"oauth_token=\"%@\",", [oauth_token urlencode]];
[authHeader appendFormat:@"oauth_verifier=\"%@\",", [oauth_verifier urlencode]];
[authHeader appendFormat:@"oauth_signature=\"%@\",", [oauthSignature urlencode]];
[authHeader appendFormat:@"oauth_version=\"%@\"", [oauthVersion urlencode]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:urlString]] ;
[request setHTTPMethod:httpMethod];
[request setValue:authHeader forHTTPHeaderField:@"Authorization"];

请帮忙...... 谢谢你提前......:)

0 个答案:

没有答案