0

Meteor内でGoogleカレンダーRESTAPIを使用しようとしていますが、任意のGETメソッドを問題なく使用できますが、カレンダーでイベントを作成しようとすると、不正アクセスエラーが発生します。

次の要点コードでコードを取得しました

基本的に、私はMeteor.loginWithGoogleを使用してAccessTokenを取得します。これを使用すると、Googleから任意のカレンダーまたはuserInfoを取得できますが、イベントを挿入しようとすると、次のメッセージが表示されます。

POST https://www.googleapis.com/calendar/v3/calendars/primary/events 401(無許可)

何か案は?

4

1 に答える 1

6

かなりの時間をかけて試してみた後、それを正しく理解しました。

次のファイルをクライアントフォルダに追加しました

 Accounts.ui.config({requestPermissions: {google: 
  ['https://www.googleapis.com/auth/calendar',
  'https://www.googleapis.com/auth/userinfo.profile',
  'https://www.googleapis.com/auth/tasks']}}, requestOfflineToken: {google: true})

gCal = 
  insertEvent: (cliente, poblacion, texto, fecha)->
  #to-do calendar devuelve un Event Object que incluye un ID
  # si incluimos este id como campo en la alerta podremos despues
  # eliminar el evento en el calendario directamente desde la app
    url = "https://www.googleapis.com/calendar/v3/calendars/primary/events"
    event=  {
      summary: cliente
      location: poblacion
      description: texto
      start:
        "date": fecha
      end:
        "date": fecha
      }
    evento = JSON.stringify event
    console.log evento
    Auth = 'Bearer ' + Meteor.user().services.google.accessToken
    Meteor.http.post url, {
      params: {key: 'INSERT-YOUR-API-KEY-HERE'},
      data: event,
      headers: {'Authorization': Auth }
      }, 
      (err, result)->
        console.log result
        return result.id

{{loginButtons}}を介してログインし、insertEventを呼び出すと、チャームのように機能します。

于 2013-01-27T00:31:17.030 に答える