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.
Related
I am trying to use Google OAuth2.0 for authentication. Everything is working fine but on initial(first) loading it is taking extra time (30 seconds-RequestTimeOut) on client side(Web-App) to load prompt. I've checked the Network Tab (Developer Console-Chrome), where I've found that it is trying to make call to
https://accounts.youtube.com/accounts/CheckConnection?pmpo=VALUE&v=VALUE×tamp=VALUE.
This request is failing with ERR_TIMED_OUT, and In my organization we don't have access to Youtube (That I'm aware of it). But Why and Where my application is making request to Youtube API is my question. If so How do I stop this (fetch accounts from youtube)?
The scope of My App goes like this
"scope": "https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
It is happening on initial load itself, later it is giving 200 status for the same request. What am I missing.
I'm completely new to this. (Sorry, If it is noob question)
Thanks in advance.
Edit::
I came to know why it is making request to youtube api, It is trying to fetch any other accounts(login users) from youtube(gmail-accounts). But how to stop making request to youtube(accounts.youtube.com). It is fine for my application to fetch accounts from google(accounts.google.com).
Thanks.
Google puts an iframe inside google o-auth account picker.
Google oauth and youtube accounts iframe
Analyzing the javascript inside that iframe, we find some evidence that, this might be an approach to load youtube session, in order to get the userId for the current logged user in Youtube.
By creating an iframe, you get the normal context of opening an website, this is, you get access to session information.
And it's exactly what this is used for, proof:
//# sourceURL=/_/mss/boq-identity/_/js/k=boq-identity.AccountsDomaincookiesCheckconnectionJs.pt_PT.4FJ4-a_ocZ8.es5.O/d=1/ct=zgms/rs=AOaEmlHUdMtrscDWG6wHCiHHFunuI9afAg/m=base
if (window.parent && window.parent.postMessage) {window.parent.postMessage( google.checkconnection.getMsgToSend('youtube', 'some_id'), 'https:\/\/accounts.google.com');}</script>
iframes can communicate, as long as one another is listening to this messages.
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
I wonder how the OAuth 2.0 redirect URI works, the App console over at Dropbox allows me to add multiple URL;s so what I really wonder is do I need to add every URL that needs access to the API?
A small exemple:
At the page index.html the user is prompt to connect to Dropbox, when connected the user is sent to app.html there the app it self is. What should then be the redirect URI, the index.html, the app.html or both?
You don't have to register each URL from which you access the API, just the one that the user is redirected back to after authorizing the app. Generally you'll only have one of these in production, but you might also use a localhost URL during development.
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.
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]]]];