Couldn't get Google custom search results using JSON - ios

I'm developing an application that makes use of Google custom search api as a feature. I added a new custom search and included some sites to search, I was able to do a search and get the results I need, but all of a sudden it stopped returning results. It returns an empty array instead. I didn't alter anything, but it looks like I have a limited number of queries, am I right?
Here's the line of code responsible for query a search word:
NSString *search = [NSString stringWithFormat:#"https://www.googleapis.com/customsearch/v1?start=1&ie=utf8&key=XXXXXX&cx=XXXXX&q=SEARHWORD&alt=json"];
url = [NSURL URLWithString:[search stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
NSURLConnection *searchConnection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
Then the normal steps of parsing the results.

if it was working fine, and then stopped all of a sudden, you may have hit the limit.
You can double check by copy-pasting
https://www.googleapis.com/customsearch/v1?start=1&ie=utf8&key=XXXXXX&cx=XXXXX&q=SEARHWORD&alt=json
in a browser and seeing the response

Related

iOS dropbox sdk / core api - listing public folder contents without authorization

I've tried checking on stackoverflow and on the api docs, but couldn't find any info pertaining to this particular question.
What I'm trying to do is getting the public folder contents of a particular dropbox account (like the /metadata function of the api), without the need to authorize/link to dropbox.
I know "/metadata/link" allows you to get metadata of a particular link without user authorization, but I couldn't find a way to get regular metadata and file listing...
Actually it doesn't even need to be a public folder (as I've read recently that dropbox discourages developers regarding relying on public folders for apps), it can just as well be a regular folder through its shared link or anything of the kind...
I'm using api v1 (but can consider changing to v2 if this is impossible with v1), although I'm not even sure if this is at all possible.
Thank you!
For future reference, if anyone needs this as well, here's how I did it:
NSString *parameters = [NSString stringWithFormat:#"?link=%#&client_id=%#&client_secret=%#",fileUrl, appKey, appSecret];
NSString *sharedPath = [NSString stringWithFormat:#"%#/%#",#"https://api.dropbox.com/1/metadata/link", parameters];
NSURL *url = [NSURL URLWithString:sharedPath];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:10];
theRequest.timeoutInterval = 5.0;
theRequest.HTTPMethod = #"POST";
NSData * resData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil];
Use NSJSONSerialization to parse resData and refer to the api documentation for json fields, and that's it.
For the sake of simplicity showing it here I used synchronous request, but it can just as easily be done with asynchronous connection delegates.

iOS url multiple statements

I have recently discovered that there is no way for me to access mysql with the pre defined iOS libraries.
So I have started making an app that has a web viewer (hidden) and will visit a url to pass the information to the database.
But I am having trouble making it so it visits a url that contains multiple variables from my objective c code my example is below.
NSURL *url = [[NSURL alloc] initWithString:#"http://webpageurl.com/updatelocation.php?friendsphonenumber=%#&yourphonenumber=%#&message=%#", _friendsPhoneNumber.text, _yourPhoneNumber.text, _message.text];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[self.WebView loadRequest:request];
This is what the url should come out looking like
http://webpageurl.com/updatelocation.php?friendsphonenumber=1112223333&yourphonenumber=1112223333&message=hioehfoi
But my code is returning a error and I am a little unsure why any and all help is greatly appreciated.

How to get WOEID without using yahoo services?

Is there any other alternative to get WOEID of a place, other than yahoo services? Is there any third party library which is free?
You can get it by making a query request using the city name you want and hitting yahoo service with code like this:
NSString *request = [NSString stringWithFormat:#"http://query.yahooapis.com/v1/public/yql?q=select * from geo.places where text=\"%#\"&format=xml", cityName];
NSString *encRequest = [request stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *URL = [NSURL URLWithString:encRequest];
I've put the complete example for this in github, but this is a solution just for testing purposes. You should use the official way (and pay if needed) for a commercial app.

PhoneGap/ChildBrowser - POST App Form to ChildBrowser

I am building an iPhone App using PhoneGap. I am using ChildBrowser plugin.
If I have a form in the App with username/pass, is there anyway I can post those information to an URL like www.mydomain.com/login.php and open it in ChildBrowser?
Please let me know.
Thanks.
You can certainly pass GET parameters to childBrowser.showWebPage().
You could intercept the submit of your form in your app and gather up the field names and values passed (assuming this is a login form, so say username and password) and pass them as parameters to the URL opened in ChildBrowser.
childBrowser.showWebPage('https://www.mydomain.com/login.php?username='+username+'&password='+password)
This is a rather unsophisticated version for demonstration purposes. It wouldn't take much to make it better.
The catch is of course that it is being sent via GET. If your login form is expecting POST and you can't change that, you could have a problem.
Edit:
If POST is your only option, perhaps you would be better off using AJAX to post to the form instead of using child browser.
I was looking for a solution, and ended developing it. This doesn't come out of the box in childbrowser for iPhone.
So, here the code that I added to the plugin.
FYI, data should be a string with the format: arg1=value1&arg2=value2&foo=bar
ChildbrowserViewController
I've added the following method there:
- (void)postURL:(NSString*)url data:(NSString*)data{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: [NSURL URLWithString:url]];
[request setHTTPMethod: #"POST"];
[request setHTTPBody: [data dataUsingEncoding: NSUTF8StringEncoding]];
[webView loadRequest: request];
webView.hidden = NO;}
ChildbrowserCommand
I've added the following code in the showWebPage method:
NSString* method = [ options objectForKey:#"method"];
if ([method isEqualToString:#"POST"]){
[childBrowser postURL:url data:[options objectForKey:#"data"]];
}else{
[childBrowser loadURL:url];
}
HTH!
Milton.

iOS & Google APIs REST

I'm trying to connect to Google RESTful API's but all I get went doing so is a login screen.
My goal is to be able to create a Calendar in Google Calendars using RESTful.
I already created my API keys on Google APIs Console.
I did this:
NSString* baseURL = #"https://accounts.google.com/o/oauth2/auth?";
NSString* url = [NSString stringWithFormat:#"%#%#",baseURL,[self dictionaryToURLStringVariables:[self authParameters]]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
Auth parameters
-(NSDictionary*)authParameters
{
NSDictionary* dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:#"code",#"response_type", redirectURI,#"redirect_uri", API_ID,#"client_id", #"https://www.googleapis.com/auth/calendar",#"scope", nil];
return dictionary;
}
The response is working fine but all I get is a Google HTML login.
I checked out and google has it's own Objective-C library which is far too complicated from my point of view and is not based on iDevices but Desktop.
My 1st question is:
Is there a SIMPLE way to do it all via REST ( login, token, CRUD... ) just sending and posting requests?
e.g: http://www.googleapis.com/login?user=MY_EMAIL&password=MY_PASSWORD (<- of course not than simple / insecure but you get the idea...)
For question 1, try implementing this NSURLConnection delegate method. It allows you to supply credentials when the service asks for them.
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge

Resources