Issue with OAuth authentication for the new Basecamp Api using OAConsumer - ios

My code looks something like this :
OAConsumer *consumer = [[OAConsumer alloc] initWithKey:#"my_ClientID"
secret:#"my_Secret"];
NSURL *url = [NSURL URLWithString:#"https://launchpad.37signals.com/authorization/token"];
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
consumer:consumer
token:nil // we don't have a Token yet
realm:nil // our service provider doesn't specify a realm
signatureProvider:nil]; // use the default method, HMAC-SHA1
[request setHTTPMethod:#"POST"];
NSLog(#"USER URL : %#",[request URL]);
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:#selector(requestTokenTicket:didFinishWithData:)
didFailSelector:#selector(requestTokenTicket:didFailWithError:)];
.
- (void)requestTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data {
if (ticket.didSucceed) {
NSString *responseBody = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
OAToken *requestToken = [[OAToken alloc] initWithHTTPResponseBody:responseBody];
NSLog(#"%#",requestToken);
}
}
My Delegate method never gets a (ticket.didSucceed) Success.
Can someone tell me what I am missing here?
Thanks

It looks like you are trying to have the user authorize your app and generate the token for the first time. For this, you're using the wrong URL. From the 37Signals API:
Your app requests authorization by redirecting your user to Launchpad:
https://launchpad.37signals.com/authorization/new?type=web_server&client_id=your-client-id&redirect_uri=your-redirect-uri
The URL you are using is for getting the access token from the verification code.

Related

How to get user information in Google plus integration with iOS

Hi I am integrating google plus integration I want to fetch user information who is currently login. I am able to get token after login but I don't know how to get personal information.
I am login step by step as following this is only because I want to get login without open external browser.
Open url link in UIWebView which open login screen in View Did Load.
UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
webView.tag=99;
NSString *url = [NSString stringWithFormat:#"https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%#&redirect_uri=%#&scope=%#&data-requestvisibleactions=%#",[GPPSignIn sharedInstance].clientID,callbakc,scope,visibleactions];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
[self.view addSubview:webView];
Get call for token Login
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if ([[[request URL] host] isEqualToString:#"localhost"]) {
// Extract oauth_verifier from URL query
NSString* verifier = nil;
NSArray* urlParams = [[[request URL] query] componentsSeparatedByString:#"&"];
for (NSString* param in urlParams) {
NSArray* keyValue = [param componentsSeparatedByString:#"="];
NSString* key = [keyValue objectAtIndex:0];
if ([key isEqualToString:#"code"]) {
verifier = [keyValue objectAtIndex:1];
NSLog(#"verifier %#",verifier);
break;
}
}
if (verifier) {
NSString *data = [NSString stringWithFormat:#"code=%#&client_id=%#&client_secret=%#&redirect_uri=%#&grant_type=authorization_code", verifier,[GPPSignIn sharedInstance].clientID,secret,callbakc];
NSString *url = [NSString stringWithFormat:#"https://accounts.google.com/o/oauth2/token"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:#"POST"];
[request setHTTPBody:[data dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
receivedData = [[NSMutableData alloc] init];
} else {
// ERROR!
}
[webView removeFromSuperview];
return NO;
}
and I get the response in did recieve data
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[receivedData appendData:data];
NSLog(#"verifier %#",receivedData);}
Now after token I want to call for fetch user information who is login, Kindly guide me on this how can I achieve this target, this will be great for me.
Thanks.

Tumblr Home Page feed

I am trying to fetch Tumblr home page feed in iOS using Tumblr V2 API's.
Here is my code for the fetch feed:
-(void)requestFeed
{
OAConsumer *consumer = [[OAConsumer alloc] initWithKey:kTumblrConsumerKey
secret:kTumblrConsumerSecret];
TumblrUser *tumblrUser = [Utils currentUser];
NSString *username = (tumblrUser!=nil)?tumblrUser.username:#"";
NSString *requestUrl = [NSString stringWithFormat:#"api.tumblr.com/v2/blog/%#/posts/queue", username];
OAToken *authToken = [[OAToken alloc] initWithUserDefaultsUsingServiceProviderName:kTumblrAccessTokenDefaultsKey prefix:#"TumblrConnect"];
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:[NSURL URLWithString:requestUrl]
consumer:consumer
token:authToken
realm:nil // our service provider doesn't specify a realm
signatureProvider:nil]; // use the default method, HMAC-SHA1
[consumer release];
[authToken release];
[request setHTTPMethod:#"GET"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:#selector(FeedTicket:didFinishWithData:)
didFailSelector:#selector(FeedTicket:didFailWithError:)];
}
But i am getting below error in response.
Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL"
UserInfo=0x8a995a0
{NSErrorFailingURLStringKey=api.tumblr.com/v2/blog/coocku/posts/queue,
NSErrorFailingURLKey=api.tumblr.com/v2/blog/coocku/posts/queue,
NSLocalizedDescription=unsupported URL, NSUnderlyingError=0x8c997c0
"unsupported URL"}
Add url scheme to your url
e.g.
[NSURL URLWithString:#"http://www.api.tumblr.com/v2/blog/%#/posts/queue];
OR
[NSURL URLWithString:#"https://www.api.tumblr.com/v2/blog/%#/posts/queue];

ASIHTTPRequest + SBJSon iphone

I am working with an application where I have to request a url and I get the response accordingly
I am using ASIHTTPRequest to request the URL
here is my request
-(void)getTips {
if ([CommonFunctions networkConnected]) {
ShowNetworkActivityIndicator();
NSString *strPhp = #"staticpage.php";
NSString *strQuery = [[NSString alloc] initWithString:[NSString stringWithFormat:#"%#%#?static_id=3",GMS_URL,strPhp]];
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:strQuery]];
NSLog(#"tips url %#",request.url);
request.delegate = self;
[request setRequestMethod:#"GET"];
[request startAsynchronous];
}
}
These are my delegate methods
-(void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data {
// NSString *responseStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// NSLog(#"responseStr %#",responseStr);
SBJsonParser *json = [[SBJsonParser alloc]init];
NSLog(#"json data %#",[json objectWithData:data]);
NSMutableArray *marrData = [[json objectWithData:data] valueForKey:#"responseData"];
if([[marrData valueForKey:#"result"] isEqualToString:#"failed"]){
[CommonFunctions showAlertMessage:[marrData valueForKey:#"error"]];
}
HideNetworkActivityIndicator();
}
Here I get null data no matter whether I pass request methods GET or POST
When I check the same url in browser I get the response and a valid json from online json viewer
What are the possible reason that I am getting null data in the application
Use requestFinished: delegate.. Please try this.
-(void)requestFinished:(ASIHTTPRequest *)request
{
NSLog(#"response %#", [request responseString]);
}

How to get linkedin connections?

In my app user has a option to login to app through linkedin.after login i have to get user's connections. when i try to get users connections i am getting response as
{
"errorCode": 0,
"message": "Access to connections denied",
"requestId": "60A0DS1MZE",
"status": 403,
"timestamp": 1386682428799
}
Here is my code
-(void)GetConnectionsCall
{
NSURL *url = [NSURL URLWithString:#"http://api.linkedin.com/v1/people/~/connections"];
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(connectionsApiCallResult:didFinish:)
didFailSelector:#selector(connectionsApiCallResult:didFail:)];
}
- (void)connectionsApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
NSString *responseBody = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSLog(#"connectionsApiCallResult====%#",responseBody);
}
- (void)connectionsApiCallResult:(OAServiceTicket *)ticket didFail:(NSError *)error
{
NSLog(#"%#",[error description]);
}
if you are using OAuth Starter Kit try this . . . .
first go to https://www.linkedin.com/secure/developer edit your App scope , make sure you have checked the r_network scope .
then go to OAuthLoginView of you project , then go to -(void) requestTokenFromProvider method .
edit you scope in below lines .
OARequestParameter *nameParam = [[OARequestParameter alloc] initWithName:#"scope"
value:#"r_fullprofile+rw_nus+r_network"];
OARequestParameter * scopeParameter=[OARequestParameter requestParameter:#"scope"
value:#"r_fullprofile rw_nus r_network"];
You need to ask for permissions.. When this is not done you are not allowed to query this information.
Everything documented here: http://developer.linkedin.com/documents/connections-api

Signature_invalid error from oAuth while querying for Google Request Token in IOS

I'm using oAuth to get request Token for unregistered installed app for "latitude" scope of google, i'm getting the response string as
signature_invalid
base_string:GET&https%3A%2F%2Fwww.google.com%2Faccounts%2FOAuthGetRequestToken&oauth_consumer_key%3Danonymous%26oauth_nonce%3D1D759072-DB2B-4E21-AA23-67CADF98C14A%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1306734462%26oauth_version%3D1.0%26scope%3Dhttps%253A%252F%252Fwww.googleapis.com%252Fauth%252Flatitude%26xoauth_displayname%3DTaj%2520Vivanta
The code i used to get request token is as follows
OAConsumer *consumer = [[OAConsumer alloc] initWithKey:#"anonymous" secret:#"anonymous"];
OAMutableURLRequest *request = [[[OAMutableURLRequest alloc] initWithURL:url consumer: consumer token:token realm:nil signatureProvider: nil] autorelease];
if (!request) return;
[request setOAuthParameterName:#"scope" withValue:[#"https://www.googleapis.com/auth/latitude" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[request setOAuthParameterName:#"xoauth_displayname" withValue:#"Taj Vivanta"];
[request setHTTPMethod: #"GET"];
OADataFetcher *fetcher = [[[OADataFetcher alloc] init] autorelease];
[fetcher fetchDataWithRequest: request delegate: self didFinishSelector: success didFailSelector: fail];
Please help me to fix this, thank you
As clearly suggested by google Document the scope and xoauth_displayname parameters should in the URL but in the above code i was placing these parameters in the request header.

Resources