gpt4 book ai didi

ios - iOS 7 LinkedIn共享按钮使用oauth2.0共享的实现

转载 作者:行者123 更新时间:2023-12-01 16:44:48 25 4
gpt4 key购买 nike

我正在尝试制作一个可以与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];

}

}

}

最佳答案

Oauth共享器工具包对我有用,我刚刚解决了我的问题。确保要测试的设备的时间设置正确,因为提前5分钟的时间戳是由linkedin API授予的

关于ios - iOS 7 LinkedIn共享按钮使用oauth2.0共享的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20839078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com