google / google-api-javascript-client

Google APIs Client Library for browser JavaScript, aka gapi.
Apache License 2.0
3.22k stars 1.06k forks source link

gapi.client.load not working on iOS #226

Open emacaya opened 8 years ago

emacaya commented 8 years ago

Hello I have a problem with gapi.client.load method, my callback never called. But it is working fine on android and google chrome browser. Here's my sample code

    gapi.client.load('quicktrack', 'v1', function () {
        console.log("callback");
    }, https://xxxxx.appspot.com/_ah/api);
tuanvhuynh commented 8 years ago

Yes, me too. its not work on ios. @emacaya I do not know have you solved it yet? help me.

willcadell commented 8 years ago

+1

bochunz commented 8 years ago

Did you see any error on console?

Another way you can try is gapi.client.load('https://xxxxx.appspot.com/_ah/api/discovery/v1/apis/quicktrack/v1/rest').then(...)

See https://developers.google.com/api-client-library/javascript/reference/referencedocs#gapiclientloadurlorobject

tuanvhuynh commented 8 years ago

@bochunz nothing on console!! more: - chrome extension, safari (iphone/ipad) is ok. -simulate by phonegap developer app on android is ok.

bochunz commented 8 years ago

Did a brief search, I think this is related. Since we use iframe, you need to somehow enable iframe in PhoneGap to make the library work. http://stackoverflow.com/questions/36835993/iframe-in-a-phonegap-app-on-ios-9-3-1

tuanvhuynh commented 8 years ago

Thanks for your response, but i do not use frame, this example very simple execute a search request on youtube by youtube api v3.

bochunz commented 8 years ago

@huynhvantuan The gapi library uses iframe for network requests.

bsittler commented 8 years ago

Note that PhoneGap is also not a supported browser, and only http and https app pages are supported. See https://developers.google.com/api-client-library/javascript/start/start-js#supported-environments

tuanvhuynh commented 8 years ago

I have tried many times, but not working. YoutubeApiExample project

YoutubeApiEx/www/index.html index.html.txt YoutubeApiEx/www/js/index.js index.js.txt YoutubeApiEx/config.xml
config.xml.txt

Project Structure: phonegap_structure_pro

Console log: phonegap_error

bochunz commented 8 years ago

As @bsittler mentioned, PhoneGap is not officially supported by the gapi library. If you would like to get it work, I would still suggest first figure out if <iframe> is supported in iOS PhoneGap app. The gapi library uses iframe under the hood.

tuanvhuynh commented 7 years ago

Thanks @bochunz , I've searched and test all solutions for 3 weeks. but can not find any solution, and i found the problems caused by PhoneGap Developer App, not Youtube api or other configurations. The problem will be solved until be installed on real device (not any simulator) via TestFlight or itunes (published app). Everything work fine. Cause:

rochapablo commented 7 years ago

Same here on Windows Phone browser

fabianotavallini commented 7 years ago

I had the same problem. SOLVED adding the following directives to config.xml:

<access origin="https://*.google.com/*" />
<access origin="https://*.googleapis.com/*" />
<allow-navigation href="https://*.google.com/*" />
<allow-navigation href="https://*.googleapis.com/*" />

and wss: protocol to the Content-Security-Policy (meta tag in index.html), like this:

    <meta http-equiv="Content-Security-Policy"
        content="default-src * gap://ready file: wss:;
            script-src 'self' 'unsafe-inline' 'unsafe-eval'
                127.0.0.1:*
                http://*.google.com
                http://*.googleapis.com
                https://*.google.com
                https://*.googleapis.com;
    ">

Explaination: you have to allow iframe generated by gapi.client.load() to navigate to google APIs.