IOS 7 LinkedIn共享按钮实现使用oauth2.0共享问题

时间:2013-12-30 11:58:14

标签: ios oauth-2.0 http-post linkedin

我正在尝试创建一个与LinkedIn共享内容的简单应用程序, 在这里,我能够收到结果,没有任何错误,但我的LinkedIn时间表中没有内容。任何帮助都会被感激,这是我的代码。

-(void)JsonPostRequst:(NSData *)jsonRequestData{

Globaltoken  *token_Obj=[Globaltoken  getInstance];

NSString* shareUrl=[NSString stringWithFormat:@"https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=%@",token_Obj.token];

NSURL *url = [NSURL URLWithString:shareUrl];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60];

[request setHTTPMethod:@"POST"];

[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];

[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

[request setValue:@"x-li-format" forHTTPHeaderField:@"json"];

[request setValue:[NSString stringWithFormat:@"%d", [jsonRequestData length]] forHTTPHeaderField:@"Content-Length"];

[request setHTTPBody: jsonRequestData];

NSError *errorReturned = nil;

NSURLResponse *response =nil;

NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&errorReturned];

if (errorReturned==nil){

    NSLog(@"data =%@",result);

}else{

    NSLog(@"error =%@",errorReturned);

}

}

-(IBAction)linkedInShare:(id)sender {

NSDictionary *json = [[NSDictionary alloc] initWithObjectsAndKeys:

                        [[NSDictionary alloc]

                         initWithObjectsAndKeys:

                         @"anyone",@"code",nil], @"visibility",

    [[NSDictionary alloc]

                         initWithObjectsAndKeys:

                         @"title",@"title",

@"description",@"Description",

@"submitted-url",@"www.google.com",

@"submitted-image-url",@"http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png",

nil], @"content",

                        @"comment", @"comment", nil];



if ([NSJSONSerialization isValidJSONObject:json]) {

   NSError *error=nil;

   NSData *jsonData=[NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:&error];

    if (error==nil && jsonData !=nil) {

        [self JsonPostRequst:jsonData];

    }

}

}

1 个答案:

答案 0 :(得分:0)

Oauth分享工具包正在为我工​​作,我刚刚解决了我的问题。确保我们正在测试的设备设置正确的时间,因为提前5分钟的时间戳由linkedin API授予