我已使用OAuth 2.0
生成了Access令牌-(void)request:(NSString *)code
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:accessTokenEndPoint]];
NSString *grantType = @"authorization_code";
NSString *postParameter = [NSString stringWithFormat:@"grant_type=%@&code=%@&redirect_uri=%@&client_id=%@&client_secret=%@",grantType,code,encodedRdirectURL,linkedInKey,linkedInSecret];
NSData *postdata = [postParameter dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPMethod = @"POST";
request.HTTPBody = postdata;
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error)
{
NSHTTPURLResponse *responseHttp = (NSHTTPURLResponse*)response;
NSInteger statusCode = [responseHttp statusCode];
if (statusCode == 200)
{
NSDictionary *parsedObject = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.TokenAccess =[parsedObject objectForKey:@"access_token"];
}
}] resume];
}
这是我如何整合linkedin
- (void)viewDidLoad
{
[super viewDidLoad];
linkedInKey = @"7";
linkedInSecret = @"u";
authorizationEndPoint = @"https://www.linkedin.com/uas/oauth2/authorization";
accessTokenEndPoint = @"https://www.linkedin.com/uas/oauth2/accessToken";
_webview.delegate = self;
[self startAuthorisation];
}
-(void)startAuthorisation
{
NSString *responseType = @"code";
NSString *redirectURL = @"https://www.google.co.in";
encodedRdirectURL = [redirectURL stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.alphanumericCharacterSet];
NSString *state = @"RandomString";
NSString *scope = @"w_share";
NSString *authorizationURL = [NSString stringWithFormat:@"%@?response_type=%@&client_id=%@&redirect_uri=%@&state=%@&scope=%@",authorizationEndPoint,responseType,linkedInKey,encodedRdirectURL,state,scope];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:authorizationURL]];
[_webview loadRequest:request];
}
现在如何使用访问令牌共享图像和文本。有没有api可用?因为我不想使用linkedin sdk。
请帮忙谢谢