Ios 在共享中链接在我的应用中不起作用
嗨,我想通过我的应用程序在LinkedIn中共享文本。我的代码在下面 单击btn linkedIn共享时使用此方法。Ios 在共享中链接在我的应用中不起作用,ios,linkedin,sharing,Ios,Linkedin,Sharing,嗨,我想通过我的应用程序在LinkedIn中共享文本。我的代码在下面 单击btn linkedIn共享时使用此方法。 - (void)linkedBtnEvent { if(oAuthLoginView != nil) { oAuthLoginView.delegate = nil; oAuthLoginView = nil; } oAuthLoginView = [[OAuthLoginView alloc] initWit
- (void)linkedBtnEvent
{
if(oAuthLoginView != nil) {
oAuthLoginView.delegate = nil;
oAuthLoginView = nil;
}
oAuthLoginView = [[OAuthLoginView alloc] initWithNibName:nil bundle:nil];
oAuthLoginView.delegate=self;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(loginViewDidFinish:)
name:@"loginViewDidFinish"
object:self.oAuthLoginView];
[self presentViewController:self.oAuthLoginView animated:YES completion:nil];
}
-(void) loginViewDidFinish:(NSNotification*)notification
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self profileApiCall];
}
- (void)profileApiCall
{
NSURL *url = [NSURL URLWithString:@"https://api.linkedin.com/v1/people/~"];
OAMutableURLRequest *request =
[[OAMutableURLRequest alloc] initWithURL:url
consumer:oAuthLoginView.consumer
token:oAuthLoginView.accessToken
callback:nil
signatureProvider:nil];
[request setValue:@"json" forHTTPHeaderField:@"x-li-format"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(profileApiCallResult:didFinish:)
didFailSelector:@selector(profileApiCallResult:didFail:)];
}
- (void)profileApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
NSString *responseBody = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSDictionary *profile = [responseBody objectFromJSONString];
if ( profile )
{
NSLog(@"%@", [[NSString alloc] initWithFormat:@"%@ %@",
[profile objectForKey:@"firstName"], [profile objectForKey:@"lastName"]]);
}
// The next thing we want to do is call the network updates
[self networkApiCall];
}
- (void)profileApiCallResult:(OAServiceTicket *)ticket didFail:(NSData *)error
{
NSLog(@"%@",[error description]);
}
- (void)networkApiCall
{
NSURL *url = [NSURL URLWithString:@"https://api.linkedin.com/v1/people/~/network/updates?scope=self&count=1&type=STAT"];
OAMutableURLRequest *request =
[[OAMutableURLRequest alloc] initWithURL:url
consumer:oAuthLoginView.consumer
token:oAuthLoginView.accessToken
callback:nil
signatureProvider:nil];
[request setValue:@"json" forHTTPHeaderField:@"x-li-format"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(networkApiCallResult:didFinish:)
didFailSelector:@selector(networkApiCallResult:didFail:)];
}
- (void)networkApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
if (isSharedLinked)
{
NSLog(@"Shared Successfully");
linkedBtn.enabled = NO;
}
else
{
isSharedLinked = YES;
[self performSelector:@selector(postTextLinkedIn) withObject:nil afterDelay:1];
}
}
- (void)networkApiCallResult:(OAServiceTicket *)ticket didFail:(NSData *)error
{
NSLog(@"%@",[error description]);
}
- (void)postTextLinkedIn
{
NSURL *url = [NSURL URLWithString:@"https://api.linkedin.com/v1/people/~/shares"];
OAMutableURLRequest *request =
[[OAMutableURLRequest alloc] initWithURL:url
consumer:oAuthLoginView.consumer
token:oAuthLoginView.accessToken
callback:nil
signatureProvider:nil];
NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:
[[NSDictionary alloc]
initWithObjectsAndKeys:
@"anyone",@"code",nil], @"visibility",
@"Wow its working... Share the text in Linked In", @"comment", nil];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSString *updateString = [update JSONString];
[request setHTTPBodyWithString:updateString];
[request setHTTPMethod:@"POST"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(postUpdateApiCallResult:didFinish:)
didFailSelector:@selector(postUpdateApiCallResult:didFail:)];
}
- (void)postUpdateApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
// The next thing we want to do is call the network updates
[self networkApiCall];
}
- (void)postUpdateApiCallResult:(OAServiceTicket *)ticket didFail:(NSData *)error
{
NSLog(@"%@",[error description]);
}
这是登录后处理共享的方法。
- (void)linkedBtnEvent
{
if(oAuthLoginView != nil) {
oAuthLoginView.delegate = nil;
oAuthLoginView = nil;
}
oAuthLoginView = [[OAuthLoginView alloc] initWithNibName:nil bundle:nil];
oAuthLoginView.delegate=self;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(loginViewDidFinish:)
name:@"loginViewDidFinish"
object:self.oAuthLoginView];
[self presentViewController:self.oAuthLoginView animated:YES completion:nil];
}
-(void) loginViewDidFinish:(NSNotification*)notification
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self profileApiCall];
}
- (void)profileApiCall
{
NSURL *url = [NSURL URLWithString:@"https://api.linkedin.com/v1/people/~"];
OAMutableURLRequest *request =
[[OAMutableURLRequest alloc] initWithURL:url
consumer:oAuthLoginView.consumer
token:oAuthLoginView.accessToken
callback:nil
signatureProvider:nil];
[request setValue:@"json" forHTTPHeaderField:@"x-li-format"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(profileApiCallResult:didFinish:)
didFailSelector:@selector(profileApiCallResult:didFail:)];
}
- (void)profileApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
NSString *responseBody = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSDictionary *profile = [responseBody objectFromJSONString];
if ( profile )
{
NSLog(@"%@", [[NSString alloc] initWithFormat:@"%@ %@",
[profile objectForKey:@"firstName"], [profile objectForKey:@"lastName"]]);
}
// The next thing we want to do is call the network updates
[self networkApiCall];
}
- (void)profileApiCallResult:(OAServiceTicket *)ticket didFail:(NSData *)error
{
NSLog(@"%@",[error description]);
}
- (void)networkApiCall
{
NSURL *url = [NSURL URLWithString:@"https://api.linkedin.com/v1/people/~/network/updates?scope=self&count=1&type=STAT"];
OAMutableURLRequest *request =
[[OAMutableURLRequest alloc] initWithURL:url
consumer:oAuthLoginView.consumer
token:oAuthLoginView.accessToken
callback:nil
signatureProvider:nil];
[request setValue:@"json" forHTTPHeaderField:@"x-li-format"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(networkApiCallResult:didFinish:)
didFailSelector:@selector(networkApiCallResult:didFail:)];
}
- (void)networkApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
if (isSharedLinked)
{
NSLog(@"Shared Successfully");
linkedBtn.enabled = NO;
}
else
{
isSharedLinked = YES;
[self performSelector:@selector(postTextLinkedIn) withObject:nil afterDelay:1];
}
}
- (void)networkApiCallResult:(OAServiceTicket *)ticket didFail:(NSData *)error
{
NSLog(@"%@",[error description]);
}
- (void)postTextLinkedIn
{
NSURL *url = [NSURL URLWithString:@"https://api.linkedin.com/v1/people/~/shares"];
OAMutableURLRequest *request =
[[OAMutableURLRequest alloc] initWithURL:url
consumer:oAuthLoginView.consumer
token:oAuthLoginView.accessToken
callback:nil
signatureProvider:nil];
NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:
[[NSDictionary alloc]
initWithObjectsAndKeys:
@"anyone",@"code",nil], @"visibility",
@"Wow its working... Share the text in Linked In", @"comment", nil];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSString *updateString = [update JSONString];
[request setHTTPBodyWithString:updateString];
[request setHTTPMethod:@"POST"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(postUpdateApiCallResult:didFinish:)
didFailSelector:@selector(postUpdateApiCallResult:didFail:)];
}
- (void)postUpdateApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
// The next thing we want to do is call the network updates
[self networkApiCall];
}
- (void)postUpdateApiCallResult:(OAServiceTicket *)ticket didFail:(NSData *)error
{
NSLog(@"%@",[error description]);
}
它显示没有错误,它总是在LinkedIn中成功共享,但在LinkedIn中没有文本共享。。
请帮我解决这个问题。。。我想不出我犯了什么错误。你可以用一个很棒的库来分享LinkedIn: 或者直接从GitHub: 它有麻省理工学院的许可证,也可以用于商业项目 希望这有帮助。您需要在“范围”中添加“rw\u nus”。这只允许应用程序共享更新。。。这是你的错误否则你所有的代码都是正确的
- (void)requestTokenFromProvider
{
OAMutableURLRequest *request =
[[[OAMutableURLRequest alloc] initWithURL:requestTokenURL
consumer:self.consumer
token:nil
callback:linkedInCallbackURL
signatureProvider:nil] autorelease];
[request setHTTPMethod:@"POST"];
OARequestParameter *nameParam = [[OARequestParameter alloc] initWithName:@"scope"
value:@"r_fullprofile+r_contactinfo+r_emailaddress+r_network+r_basicprofile+rw_nus"];
NSArray *params = [NSArray arrayWithObjects:nameParam, nil];
[request setParameters:params];
OARequestParameter * scopeParameter=[OARequestParameter requestParameter:@"scope" value:@"r_fullprofile r_contactinfo r_emailaddress r_network r_fullprofile rw_nus"];
[request setParameters:[NSArray arrayWithObject:scopeParameter]];
OADataFetcher *fetcher = [[[OADataFetcher alloc] init] autorelease];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(requestTokenResult:didFinish:)
didFailSelector:@selector(requestTokenResult:didFail:)];
}
替换这是在您的oAuthloginView.m中,谢谢我提供了示例代码以共享链接中的文本,它在该示例中工作,但在我的项目中不是问题所在。问题出在哪里?oAuth可能有错误?不,它没有显示错误,也调用methodos finishUpdates,但在Linked in中没有更新…@AntonGolub:在您的代码中没有共享数据我认为这些代码中的问题与您的代码中包含的问题相同。。您的代码还显示它已成功共享,但未共享链接中的内容