我目前在我的 Python 网络应用程序中使用 oauth2client 以使用 Google 的日历 API。
我将 oauth2client 复制到我目录的根文件夹中,并按照https://developers.google.com/google-apps/calendar/instantiate 上的说明进行操作。这意味着我的代码看起来像:
import httplib2
import gflags
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
FLAGS = gflags.FLAGS
FLOW = OAuth2WebServerFlow(
client_id='myid',
client_secret='mycode',
scope='https://www.googleapis.com/auth/calendar',
user_agent='myapp/4')
storage = Storage('calendar.dat')
credentials = storage.get()
if credentials is None or credentials.invalid == True:
credentials = run(FLOW, storage)
Run Code Online (Sandbox Code Playgroud)
ID,密钥都来自我的 Google Cloud Console 帐户,所以它们应该是正确的。我在日志中看到以下错误:
ERROR 2013-12-10 14:03:33,983 api_server.py:112] Received a request without request_id: service_name: "remote_socket"
method: "Close" …Run Code Online (Sandbox Code Playgroud) 我想将Google Calendar API用于我的Google App Engine webapp.我按照此处的说明(https://developers.google.com/google-apps/calendar/instantiate)配置了应用,这需要我导入gflags.我在这里下载了gflags(https://code.google.com/p/python-gflags/downloads/list)并将其解压缩到与我的webapp的main.py相同的目录中.然后我通过在命令行中运行"Python setup.py install"来设置gflags.设置成功,显示以下内容:
已安装c:\ python27\lib\site-packages\python_gflags-2.0-py2.7.egg
处理python-gflags == 2.0的依赖关系
完成了对python-gflags == 2的处理依赖性.
但是这条线仍然不起作用:
import gflags
Run Code Online (Sandbox Code Playgroud)
我在日志中收到以下错误:
NotImplementedError:必须安装gflags库才能使用tools.run().请安装gflags或者最好切换到使用tools.run_flow()
但我以为我已经安装了gflags?我也很困惑为什么setup.py在我的c:\ python27\lib文件夹中创建了一个Python egg,这是否意味着Google App Engine将无法访问它?