[英]issue regarding Integrate Linkedin in ios
我是新手,需要在我的應用程序中集成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;
}
[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];
}
];
希望這對您有幫助
在您的ViewController中為UIButton創建一個插座
在您的info.plist中,在LSApplicationQueriesSchemes下添加以下內容
還要在plist文件中添加您的Linkedin應用程序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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.