我是新手,需要在我的应用程序中集成linkedin。我已经生成了客户端ID和客户端密钥。我已经阅读了linkedin的文档,但每次我收到一些错误,请引导我完成同样的操作。 对于获取请求,我已经尝试了这个,但不知道在里面写什么
[[LISDKAPIHelper sharedInstance]getRequest:(NSString *)url success:^(LISDKAPIResponse *) {
} error:^(LISDKAPIError *)
{
}];
我甚至写在AppDelegate
班
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if ([LISDKCallbackHandler shouldHandleUrl:url]) {
return [LISDKCallbackHandler application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}
return YES;
}
答案 0 :(得分:0)
[LISDKSessionManager createSessionWithAuth:[NSArray arrayWithObjects:LISDK_W_SHARE_PERMISSION, nil]
state:@"some state"
showGoToAppStoreDialog:YES
successBlock:^(NSString *returnState) {
NSLog(@"%s","success called!");
NSLog(@"Access Token: %@", [[[LISDKSessionManager sharedInstance] session].accessToken description]);
NSString *url = @"https://api.linkedin.com/v1/people/~/shares";
NSString *str = @"Your String";
NSString *payload = @"Your Payload";
if ([LISDKSessionManager hasValidSession]) {
[[LISDKAPIHelper sharedInstance] postRequest:url stringBody:payload
success:^(LISDKAPIResponse *response) {
// do something with response
NSLog(@"%s","success called!");
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Linkedin" message:@"Shared successfully." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
}
error:^(LISDKAPIError *apiError) {
// do something with error
NSLog(@"%s","error called!"); UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Oops!" message:@"There was a problem sharing. Please try again later." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
}];
}
}
errorBlock:^(NSError *error) {
NSLog(@"%s %@","error called! ", [error description]);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Oops!" message:@"There was a problem sharing. Please try again later." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
}
];
希望这可以帮助你
答案 1 :(得分:0)
在ViewController中为UIButton创建一个插座
在您的info.plist中添加以下LSApplicationQueriesSchemes
还要在plist文件中添加您的linkedin app id。在ViewController中执行以下操作:
-(void) linkedinTap{
NSArray *permissions = [NSArray arrayWithObjects:LISDK_BASIC_PROFILE_PERMISSION, nil];
[LISDKSessionManager createSessionWithAuth:permissions state:nil showGoToAppStoreDialog:YES successBlock:^(NSString *returnState)
{
NSLog(@"%s","success called!");
LISDKSession *session = [[LISDKSessionManager sharedInstance] session];
NSLog(@"Session : %@", session.description);
} errorBlock:^(NSError *error)
{
NSLog(@"%s","error called!");
}];
}
-(void) getRequest:(NSString*)token{
[[LISDKAPIHelper sharedInstance] getRequest:@"https://api.linkedin.com/v1/people/~"
success:^(LISDKAPIResponse *response)
{
NSData* data = [response.data dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dictResponse = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSLog(@"Authenticated user name : %@ %@", [dictResponse valueForKey: @"firstName"], [dictResponse valueForKey: @"lastName"]);
} error:^(LISDKAPIError *apiError)
{
NSLog(@"Error : %@", apiError);
}];
}
在你的AppDelegate
中- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [LISDKCallbackHandler application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
return YES;
}