In Google's JavaScript API's, what's the difference between gapi.load() and gapi.client.load()? How interchangeable are they and when should I use one versus the other? I see both are used in the Google Drive Realtime API sample code.
            Asked
            
        
        
            Active
            
        
            Viewed 1.1k times
        
    2 Answers
12
            
            
        As indicated by the CORS documentation, the gapi.load function is used to dynamically load specific JavaScript libraries.
As documented in the description of the gapi.client.load function (which is provided by the "client" JS library), gapi.client.load is used to build a JavaScript interface for accessing specific HTTP(S) APIs; you can also do this sort of thing yourself using API discovery (search for it to find docs) and sending API requests directly with gapi.client.request or CORS.
Edit: added clarification based on Brian Slesinsky's follow-up comment and made minor wording changes.
 
    
    
        Community
        
- 1
- 1
 
    
    
        Ben Sittler
        
- 264
- 1
- 2
- 6
- 
                    1To clarify, by "API" I assume you mean HTTP(S) API's? After all any JavaScript library has an API. – Brian Slesinsky Jun 01 '13 at 04:13
2
            
            
        After researching this, here's my simple take:
- gapi.load()loads the JavaScript client library. That is to say, it's loading- gapi. Without this- gapiwon't work.
- gapi.client.load()is for loading an interface for one of the many Google APIs. The loaded API interface will then be in the form- gapi.client.api.collection.method. For example, the Moderator API would create methods like- gapi.client.moderator.series.list.
You most likley need both.
 
    
    
        TinyTiger
        
- 1,801
- 7
- 47
- 92
