Authorizing requests with OAuth 2.0 in Google Spreadsheet API

后端 未结 4 1178
一个人的身影
一个人的身影 2021-01-06 05:08

I am trying to create a PHP web page that requires reading some data from a google spreadsheet in my domain (I am using Google Apps Free Edition).

The spreadsheet t

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-06 05:33

    You can use the new provided oauth2 flow

    //flow use httpTransport, clientSecrets, json factory and datastore factory
    val flow = new GoogleAuthorizationCodeFlow
      .Builder(httpTransport,JSON_FACTORY,clientSecrets,SCOPES)
      .setDataStoreFactory(datastoreFactory)
      .build()
    
    // authorize
    val credential=new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user")
    

    and use it with your gdata service:

    val service:SpreadsheetService=new SpreadsheetService("SpreadsheetIntegration") 
     service.setOAuth2Credentials(credential)
    

    full example in scala: https://github.com/spaced/spreadsheet-oauth2-example

提交回复
热议问题