0

我没有使用客户端库,而是直接使用 REST。我已经成功创建了谷歌登录。我保存用户的 access_token。当我尝试创建新事件并将其插入用户日历时,我使用 access_token (在此代码中是硬编码的)。这是我的代码

def google_get_list(request):
    parser = httplib2.Http()
    uri = "https://www.googleapis.com/calendar/v3/calendars/primary/events?key={YOUR_API_KEY}"\
        .format(YOUR_API_KEY='AIzaSyD_Axx9SGH0Y71xxxxxxxxxxxxxxxxxxxxx')
    params = urllib.urlencode({
        "summary": "Test Calendar",
    })
    headers = {'Content-Type': 'application/json', 
               'Authorization':  'Bearer ya29.AHES6ZQdFo8IXu5gAns8qEiyLbcbZxxxxxxxxxxxxxxxxxxxxxxxxxx',
               'X-JavaScript-User-Agent':  'Google APIs Explorer'
               }
    resp, content = parser.request(uri, method='POST', body=params, headers=headers)
    print content
    return HttpResponseRedirect('/')

接收(打印)的内容是

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "parseError",
    "message": "Parse Error"
   }
  ],
  "code": 400,
  "message": "Parse Error"
 }
} 

有什么帮助吗?

4

0 回答 0