Giter Site home page Giter Site logo

Comments (7)

rubenCodeforges avatar rubenCodeforges commented on June 6, 2024

as far as i know there is only one gapi provided by google if you try to load it twice it will overide itself.
so in general you cant and i guess you should not even try it.

from ng-gapi.

sahlouls avatar sahlouls commented on June 6, 2024

yes, there is only one gapi but it is possible to have multiple clients. For example: a web application that will need to use custom endpoints + public apis then there is the need to have multiple clients one for each.

from ng-gapi.

rubenCodeforges avatar rubenCodeforges commented on June 6, 2024

@sahlouls can you give an example on how you want to use gapi ?
I just dont get what you want to achieve.
are you trying to have 2 instances of gapi.client or are you trying to include 2 gapi libraries ?

from ng-gapi.

sahlouls avatar sahlouls commented on June 6, 2024

I have an application running on appengine. I use cloud endpoints so I need a gapi client (1st client). In the same time I need to interact with other services (Google+, Drive, etc ) and for these I need also other gapi clients.
Yes: How can I have multiple instances with differents configuration of gapi.client ?

from ng-gapi.

rubenCodeforges avatar rubenCodeforges commented on June 6, 2024

Ok i got it.
So in general ng-gapi is injecting the gapi lib in to the dom and fires next() when its loaded (Observable)
this is done in https://github.com/rubenCodeforges/ng-gapi/blob/master/src/GoogleApiService.ts

As you can see the configs are just saved here , they are not used in this service.
Now if you take a look at https://github.com/rubenCodeforges/ng-gapi/blob/master/src/GoogleAuthService.ts#L28 here is where the config is used.

Let assume you have a default config which is used for the ng-gapi authService.
What you can now do is create a similar class :

@Injectable()
export class GoogleAuthService {
    private MyNewGoogleServiceOrClientOrWhatever: any = undefined;

    constructor(private googleApi: GoogleApiService) {
        this.googleApi.onLoad().subscribe(() => {
            // Reference https://developers.google.com/api-client-library/javascript/reference/referencedocs
            gapi.load('client:auth2', () => {
                let newConfigs: NgGapiClientConfig = {
                    client_id: "CLIENT_ID",
                    discoveryDocs: ["https://analyticsreporting.googleapis.com/$discovery/rest?version=v4"],
                    scope: [
                        "https://www.googleapis.com/auth/analytics.readonly",
                        "https://www.googleapis.com/auth/analytics"
                    ].join(" ")
                };
                let newService = gapi.whateverServiceYouWant.init(newConfigs);
                this.MyNewGoogleServiceOrClientOrWhatever = newService;
            });
        };
    }
}

This is just a rough example , but you should get the idea.

In general ng-gapi gives you the possibility to use gapi as Angular service and access it via observable

from ng-gapi.

sahlouls avatar sahlouls commented on June 6, 2024

Hi Ruben,

Thanks for the reply, I will give it a try and let you know.

from ng-gapi.

rubenCodeforges avatar rubenCodeforges commented on June 6, 2024

you are welcome , if it worked for you just close the issue

from ng-gapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.