[英]Instagram API Implementation failed in iOS
I'm implementing Instagram API
Sample in my iOS
app. 我正在我的iOS
应用中实现Instagram API
示例。 I registered my app in Instagram Website
. 我在Instagram Website
注册了我的应用程序。 I got client id
and secret
everything after that I'm implementing in my project. 在项目中实施之后,我得到了client id
并对其进行了secret
。 But I can't share my photos. 但是我不能分享我的照片。
My Code is: 我的代码是:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.title = @"Instagram Login";
NSString* urlString = [kBaseURL stringByAppendingFormat:kAuthenticationURL,kClientID,kRedirectURI];
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
NSLog(@"%@",urlString);
NSLog(@"%@",request);
if (![UIUtils checkNetworkConnection])
return;
[_webView loadRequest:request];
}
#pragma mark -- WebView Delegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString* urlString = [[request URL] absoluteString];
NSURL *Url = [request URL];
NSArray *UrlParts = [Url pathComponents];
if ([UrlParts count] == 1)
{
NSRange tokenParam = [urlString rangeOfString:kAccessToken];
if (tokenParam.location != NSNotFound)
{
NSString* token = [urlString substringFromIndex: NSMaxRange(tokenParam)];
// If there are more args, don't include them in the token:
NSRange endRange = [token rangeOfString: @"&"];
if (endRange.location != NSNotFound)
token = [token substringToIndex: endRange.location];
if ([token length] > 0 )
{
// call the method to fetch the user's Instagram info using access token
[_gAppData getUserInstagramWithAccessToken:token];
}
}
else
{
DLog(@"rejected case, user denied request");
}
return NO;
}
return YES;
}
- (void) webViewDidStartLoad:(UIWebView *)webView
{
[_gAppDelegate showLoadingView:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[_gAppDelegate showLoadingView:NO];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
DLog(@"Code : %d \nError : %@",error.code, error.description);
//Error : Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted"
if (error.code == 102)
return;
if (error.code == -1009 || error.code == -1005)
{
// _completion(kNetworkFail,kPleaseCheckYourInternetConnection);
}
else
{
// _completion(kError,error.description);
}
[UIUtils networkFailureMessage];
}
The following Error log show in my project: 我的项目中显示以下错误日志:
headers: (null) }
2014-11-18 16:42:07.128 InstragramSample[376:27732] -[SignInViewController webView:didFailLoadWithError:] [Line 94] Code : 101
Error : Error Domain=WebKitErrorDomain Code=101 "The URL can’t be shown" UserInfo=0x1551cd30 {NSErrorFailingURLKey=ige99d3bcd754b49b6ad543375c4a3edaa://authorize#access_token=1558091028.e99d3bc.889f10ef7ff64fc8938ed6de9d8978f8, NSErrorFailingURLStringKey=ige99d3bcd754b49b6ad543375c4a3edaa://authorize#access_token=1558091028.e99d3bc.889f10ef7ff64fc8938ed6de9d8978f8, NSLocalizedDescription=The URL can’t be shown}
2014-11-18 16:42:07.344 InstragramSample[376:27732] -[SignInViewController webView:didFailLoadWithError:] [Line 94] Code : 102
Error : Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted" UserInfo=0x16f38000 {NSErrorFailingURLKey=ige99d3bcd754b49b6ad543375c4a3edaa://authorize#access_token=1558091028.e99d3bc.889f10ef7ff64fc8938ed6de9d8978f8, NSErrorFailingURLStringKey=ige99d3bcd754b49b6ad543375c4a3edaa://authorize#access_token=1558091028.e99d3bc.889f10ef7ff64fc8938ed6de9d8978f8, NSLocalizedDescription=Frame load interrupted}
The error is pretty explicit: the webview could not load the URL ige99d3bcd754b49b6ad543375c4a3edaa://authorize#access_token=1558091028.e99d3bc.889f10ef7ff64fc8938ed6de9d8978f8
. 该错误非常明显: ige99d3bcd754b49b6ad543375c4a3edaa://authorize#access_token=1558091028.e99d3bc.889f10ef7ff64fc8938ed6de9d8978f8
无法加载URL ige99d3bcd754b49b6ad543375c4a3edaa://authorize#access_token=1558091028.e99d3bc.889f10ef7ff64fc8938ed6de9d8978f8
。
There are fundamental problems with how you're attempting to construct and parse URLs. 尝试构造和解析URL时存在一些基本问题。 Take a moment to revisit the documentation for NSURL
and NSURLComponents
. 花一点时间重新阅读NSURL
和NSURLComponents
的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.