iOS: Display Google Search Results in UIWebView without API - ios

I have an iOS app where a user can select a keyword, and the app will display search results from Google via an in-app UIWebView.
e.g. A user selects my term name, I construct this URL: https://www.google.com/search?q=my+term+name, and open that URL in a UIWebView.
Is this against Google's terms of service? Do I need to include any sort of authentication credentials in the URL?
Thanks.

If you are just displaying a google web page, then that's fine. All you've done is construct a URL and display the results. If you were parsing / scraping the results, then you'd have a legal issue. If it were a problem services such as lmgtfy would not be legal.

Very simple.... Try this:
Google Search = http://google.com/search?q=ios
For other search engines:
Yahoo Search = http://search.yahoo.com/?q=ios
Bing Search = http://www.bing.com/search?q=ios
Ask Search = http://www.ask.com/web?q=ios

Scrapping results directly from goog html is a violation of their TOS.
Clause 5.3 Google TOS:
"You specifically agree not to access (or attempt to access) any of the Services through any automated means (including use of scripts or web crawlers)..."

No, It does not requires any authentication credentials or some certificate to view the Google links in your ios devices.
I you think it will have any problems then you can make multiple webpages and use them in iOS using phoneGap.

You could use
-(void)recivedRequest {
//load the request to a web view
[webView loadRequest:[NSUrlConnection connectionWithURL:[URL urlWithString:[NSString stringWithFormat:#"http://www.google.com/search?q=my+term+name"]]]];
Or if you want to create a string before loading the request, you can do that:
-(void)recivedRequest {
//create a NSString with the keyword
NSString *keyWord = #"my+term+name";
//load the request to a web view
[webView loadRequest:[NSUrlRequest requestWithURL:[NSURL urlWithString:[NSString stringWithFormat:#"http://www.google.com/search?q=%#", keyWord]]]];

Related

Passing parameters in Google News app URL scheme

I want to integrate the Google News app with another iOS customized app. I've found the URL scheme for Google News (googlenews://) and it opens the app. Now I am trying to pass a parameter in order to automatically search news for it. I've used the following URLs with no success.
googlenews://news.google.com/search?q=stackoverflow
googlenews://q=stackoverflow
googlenews://?q=stackoverflow
Looks simple but it doesn't work. How to do that correctly?
If you want a parameter search to Google News, you can try the following:
https://news.google.com/news/section?cf=all&hl=us&ned=en_us&q=<YOUR_SEARCH_TERM>
Where <YOUR_SEARCH_TERM> is the parameter you want search.

iOS iFrame in UIWebView Uses basic authentication but no popup shows?

Our app has a UIWebView with an iFrame inside it, and the website the iframe points to requires basic authentication.
In a browser the alert popup displays and allows us to log in, however in the UIWebView it does not.
Is there a setting or something we've missed?
Chris
As stated in the official Developer forums and as for now, UIWebView does not support authentication challenges in iOS. Please read here (requires developer account): UIWebView does not directly support authentication challenges
A workaround is to load the html in NSURLConnection (or NSURLSession), execute the authentication challenge and then assign the data the web view.
That won't work in all scenarios, though.
Some time iFrame URL try to load from the cache.
Try to set the response header Cache-Control:no-cache.
401 Authorization requests will be blocked because of the cross-origin request

Use Google Drive API to view files in iOS

I am currently working on a project wherein one of the requirements is to view a users Google Drive files on an iOS device. The SDK is all setup with oAuth 2.0 authentication and appropriate scopes. I've already pulled Google Plus, Calendar, and Drive data, but viewing the actual Drive files is proving to be harder than expected.
Currently i've got a table view with a list of all your Google Drive files, the idea is that when you click on them it should load the file.
Right now i've got a "DriveFileViewController", in it i've written:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.requestURL]];
[self.webView loadRequest:request];
[self.view setNeedsDisplay];
The self.requestURL in that case is the defaultOpenWithLink that Google lists in their API explorer at http://developers.google.com/apis-explorer/#p/drive/v2/drive.files.get.
The problem then is that the webView loads the requested URL but Google is asking for users to sign in again in the webView rather than showing them the file.
On my Mac, on the browser if you're authenticated and you click on the link from the API explorer it will work fine.
Im assuming their is some kind of cookie or header field that I need to set in my URL Request to let Google know the user is authenticated already and that they should be able to view their file.
Any help would be greatly appreciated.
You can use the access token as an Authorization header when loading an embedLink into a WebView.
Authorization: Bearer <access_token>
It will authorize the document with the same user authorized and authenticated on the app.

Setting up YouTube access within app, stuck on retrieving url response

I can't find any answers or similar questions to my YouTube API puzzle and hoping someone can help.
My iOS app, which makes a video within it, needs to connect to a user's YouTube account so they can upload the video for others to see etc.
I've followed the API documentation and managed to connect to the authentication part where the user logs into their account, (code I used posted below).
It works in the sense it takes user to the login page for Google, when logged in the page asks if the user would like to authorise the app access to account, etc. When the user accepts though, I understand there should be data returned which gives the app authentication, the token code, so it can be used to upload videos later within the app.
My question is.... How do I retrieve this data? When I click accept it simply takes me to another webpage, but I don't know where to retrieve the info.
Thanks in advance for anyone who can point me in the right direction.
#define kAuthUrl #"https://accounts.google.com/o/oauth2/auth?"
#define kClientID #"client_id=xxxxxxxxxxxMyUniqueIDDetailsxxxxxxxxxx&"
#define kRediretUri #"redirect_uri=urn:ietf:wg:oauth:2.0:oob&"
#define kScopeUL #"scope=https://www.googleapis.com/auth/youtube.upload&"
#define kResponse #"response_type=code"
Above code placed in header file.
- (void)viewDidLoad
{
NSString *loginURL = [NSString stringWithFormat:#"%#%#%#%#%#", kAuthUrl, kClientID, kRediretUri, kScopeUL, kResponse];
NSURLRequest * urlReq = [NSURLRequest requestWithURL: [NSURL URLWithString:loginURL]];
[_webView loadRequest:urlReq];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
From the YouTube API documentation it says
When this value is used, your application can sense that the page has loaded and the title of the HTML page contains the authorization code. It is then up to your application to close the browser window if you want to ensure that the user never sees the page that contains the authorization code. The mechanism for doing this varies from platform to platform.
Where "this value" refers to the redirect_uri I chose, as opposed to a local host redirect.
How can I sense the user has logged on to their account and pressed the "accept" button, and this now also leads me on to asking how to know this and then retrieve the code from the returned url while closing the browser.
Cheers, Jim.
My strong recommendation is to use the Google Toolbox for Mac OAuth 2 Controllers project to handle all the details of your OAuth 2 integration for you.

Link on Facebook with custom prefix/protocol (like myapp://blahblah)

I added to my iOS application option to detect and response to custom URL schemes to launch application ( http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html ).
Link is working perfectly on different sites (using href), but I'm having problem with Facebook. If I'm trying to post link (using Graph API) which looks like:
myapp://blabla
Facebook return error:
The url you supplied is invalid
And for feed with link return
link URL is not properly formatted.
I can't just post url as a message because it's not being detected as a URL and appear like text only.
Is there any way to post to Facebook wall with custom links?
Edit:
I have an idea, but I don't know if it gonna work. Putting
myapp://blabla directly into address field in mobile browser is launching application so probably accessing an webpage (like http://www.mywebpage/myapp) with only redirection to
myapp://blabla gonna work too, but is Facebook gonna accept that link?
I think your suggestion in the edit is the correct method, and should work. However applications like spotify seem to use an intersticial page which fires the "app link" with javascript, the advantage to this approach is that you can use that page to "sell" the app to users who don't have it and also provide lovely open graph tags for people who want to share it.

Resources