Instagram login in phonegap ios
Instagram login in phonegap ios
我是电话间隙的新手。我正在尝试为Phone-gapiphone实现Instagram登录。fcinfg 调用我正在使用的插件.cordova2.9.0 版本的方法的一些问题。下面是以下代码:
CDVInstagram插件.js
function startLogin(response)
{`enter code here`
cordova.exec(onInstaComplete, onInstaNotComplete, 'LoginViewController', 'initWithWebView', []);
}
// LoginViewController.h
#import <UIKit/UIKit.h>
@interface LoginViewController : UIViewController<UIWebViewDelegate>
{
IBOutlet UIWebView *loginWebView;
IBOutlet UIActivityIndicatorView* loginIndicator;
IBOutlet UILabel *loadingLabel;
}
@property(strong,nonatomic)NSString *typeOfAuthentication;
-(void)startLogin;
@end
LoginViewController.m
// InstagramUnsignedAuthentication
#import "LoginViewController.h"
#import "AppDelegate.h"
#define INSTAGRAM_AUTHURL @"https://api.instagram.com/oauth/authorize/"
#define INSTAGRAM_APIURl @"https://api.instagram.com/v1/users/"
#define INSTAGRAM_CLIENT_ID @"808a4481a80a4f9da83d3596d9e90a53"
#define INSTAGRAM_CLIENTSERCRET @"a997b61ab50847278170344873ddcb3b"
#define INSTAGRAM_REDIRECT_URI @"http://localhost/newdata/"
#define INSTAGRAM_ACCESS_TOKEN @"access_token"
#define INSTAGRAM_SCOPE @"likes+comments+relationships"
@interface LoginViewController ()
@end
@implementation LoginViewController
@synthesize typeOfAuthentication;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear: animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
-(void)initWithWebView//:(UIWebView *)web
{
NSLog(@"Startlogin call");
[[UIApplication sharedApplication] setStatusBarHidden:YES];
// loginWebView=web;
loginWebView = [[UIWebView alloc]initWithFrame:self.view.frame];
NSString* authURL = nil;
if ([typeOfAuthentication isEqualToString:@"UNSIGNED"])
{
authURL = [NSString stringWithFormat: @"%@?client_id=%@&redirect_uri=%@&response_type=token&scope=%@&DEBUG=True",
INSTAGRAM_AUTHURL,
INSTAGRAM_CLIENT_ID,
INSTAGRAM_REDIRECT_URI,
INSTAGRAM_SCOPE];
}
else
{
authURL = [NSString stringWithFormat: @"%@?client_id=%@&redirect_uri=%@&response_type=code&scope=%@&DEBUG=True",
INSTAGRAM_AUTHURL,
INSTAGRAM_CLIENT_ID,
INSTAGRAM_REDIRECT_URI,
INSTAGRAM_SCOPE];
}
[loginWebView setDelegate:self];
[loginWebView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: authURL]]];
}
#pragma mark -
#pragma mark delegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
return [self checkRequestForCallbackURL: request];
}
- (void) webViewDidStartLoad:(UIWebView *)webView
{
[loginIndicator startAnimating];
loadingLabel.hidden = NO;
[loginWebView.layer removeAllAnimations];
loginWebView.userInteractionEnabled = NO;
[UIView animateWithDuration: 0.1 animations:^{
// loginWebView.alpha = 0.2;
}];
}
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
[loginIndicator stopAnimating];
loadingLabel.hidden = YES;
[loginWebView.layer removeAllAnimations];
loginWebView.userInteractionEnabled = YES;
[UIView animateWithDuration: 0.1 animations:^{
//loginWebView.alpha = 1.0;
}];
}
- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[self webViewDidFinishLoad: webView];
}
#pragma mark -
#pragma mark auth logic
- (BOOL) checkRequestForCallbackURL: (NSURLRequest*) request
{
NSString* urlString = [[request URL] absoluteString];
if ([typeOfAuthentication isEqualToString:@"UNSIGNED"])
{
// check, if auth was succesfull (check for redirect URL)
if([urlString hasPrefix: INSTAGRAM_REDIRECT_URI])
{
// extract and handle access token
NSRange range = [urlString rangeOfString: @"#access_token="];
[self handleAuth: [urlString substringFromIndex: range.location+range.length]];
return NO;
}
}
else
{
if([urlString hasPrefix: INSTAGRAM_REDIRECT_URI])
{
// extract and handle access token
NSRange range = [urlString rangeOfString: @"code="];
[self makePostRequest:[urlString substringFromIndex: range.location+range.length]];
return NO;
}
}
return YES;
}
-(void)makePostRequest:(NSString *)code
{
NSString *post = [NSString stringWithFormat:@"client_id=%@&client_secret=%@&grant_type=authorization_code&redirect_uri=%@&code=%@",INSTAGRAM_CLIENT_ID,INSTAGRAM_CLIENTSERCRET,INSTAGRAM_REDIRECT_URI,code];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
NSMutableURLRequest *requestData = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString:@"https://api.instagram.com/oauth/access_token"]];
[requestData setHTTPMethod:@"POST"];
[requestData setValue:postLength forHTTPHeaderField:@"Content-Length"];
[requestData setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[requestData setHTTPBody:postData];
NSURLResponse *response = NULL;
NSError *requestError = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:requestData returningResponse:&response error:&requestError];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:nil];
[self handleAuth:[dict valueForKey:@"access_token"]];
}
- (void) handleAuth: (NSString*) authToken
{
NSLog(@"successfully logged in with Tocken == %@",authToken);
}
@end
配置.xml
<feature name="LoginViewController">
<param name="ios-package" value="LoginViewController" />
</feature>
@subir,
您正在使用过时的代码示例。
你已经命中:
刚接触Cordova/Phonegap的开发人员犯的主要错误
你已经打了 11. 和 12。
11. 您现在需要从 NPM 获取插件。
有关采购插件的规则可能相当混乱。最好的办法是阅读下面的博客文章。使用 CLI 的开发人员可以从 github 获取源代码,再次请参阅博客文章。
2015-10-09 - 在没有公告、推文或博客的情况下,存储库会在计划前整整一周更改。我什么也做不了,只能抱怨。这的烦人。
- 新
- 新 科尔多瓦 npm 搜索页面
- 新的科尔多瓦核心插件
最新版本的插件 六月 22, 2015
与#11相关的博客文章
- 科尔多瓦插件注册表变得不可变 2015/09/08 插件
- 发布和将插件移动到 npm 2015/04/21
- 最新*核心*插件及其版本列表 六月 22, 2015
12. <feature>
已弃用
<feature>
标记已弃用。这意味着它们不再使用。 你可以在这里阅读它
相关文章:
- 压缩phonegap中ios的图像插件
- Phonegap iOS-设备准备不发射其他事件做
- 建立phonegap/cordova iOS p2p视频聊天
- 无法在iOS模拟器上运行简单的基于KineticJs的Cordova/PhoneGap应用程序
- 在Phonegap/iOS中按下主页按钮时访问本地存储
- Phonegap BarcodeScanner.js可以'不要关闭ios
- 如何通过Phonegap使用iOS格式查找联系人的电话号码
- PhoneGap/Cordova 日历 iOS 插件不发送信息
- json格式作为cordova或phonegap ios插件的参数
- 无法在Phonegap iOS中的document.cookie中设置域
- 在IOS(Phonegap)中按姓名对联系人进行排序(姓名显示为中文和英文)
- 为什么jquery append没有'不适用于phonegap ios
- iOS Phonegap网页链接嵌入iframe开放系统浏览器,而不是iframe
- iOS PhoneGap 调试工作流
- iOS Phonegap使用手势进行滑动检测
- 在使用iOS Phonegap包装的jQuery Mobile中找不到具有相对src的图像
- HTML5本地存储功能在我的IOS Phonegap应用程序中突然停止工作
- ios phonegap禁止过度滚动无法正常工作
- 当屏幕键盘出现时保留页面布局(iOS/phonegap)
- HTML5, JS, iOS phonegap应用上的图像注释