Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有没有一种不用API密钥就可以与Google API通信的方法?_Python_Google App Engine_Python 2.7_Google Calendar Api - Fatal编程技术网

Python 有没有一种不用API密钥就可以与Google API通信的方法?

Python 有没有一种不用API密钥就可以与Google API通信的方法?,python,google-app-engine,python-2.7,google-calendar-api,Python,Google App Engine,Python 2.7,Google Calendar Api,我有一个非常简单的应用程序,我从中复制并粘贴到下面: import gflags import httplib2 from apiclient.discovery import build from oauth2client.file import Storage from oauth2client.client import OAuth2WebServerFlow from oauth2client.tools import run FLAGS = gflags.FLAGS # Set

我有一个非常简单的应用程序,我从中复制并粘贴到下面:

import gflags
import httplib2

from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run

FLAGS = gflags.FLAGS

# Set up a Flow object to be used if we need to authenticate. This
# sample uses OAuth 2.0, and we set up the OAuth2WebServerFlow with
# the information it needs to authenticate. Note that it is called
# the Web Server Flow, but it can also handle the flow for native
# applications
# The client_id and client_secret can be found in Google Developers Console
FLOW = OAuth2WebServerFlow(
    client_id='YOUR_CLIENT_ID',
    client_secret='YOUR_CLIENT_SECRET',
    scope='https://www.googleapis.com/auth/calendar',
    user_agent='YOUR_APPLICATION_NAME/YOUR_APPLICATION_VERSION')

# To disable the local server feature, uncomment the following line:
# FLAGS.auth_local_webserver = False

# If the Credentials don't exist or are invalid, run through the native client
# flow. The Storage object will ensure that if successful the good
# Credentials will get written back to a file.
storage = Storage('calendar.dat')
credentials = storage.get()
if credentials is None or credentials.invalid == True:
  credentials = run(FLOW, storage)

# Create an httplib2.Http object to handle our HTTP requests and authorize it
# with our good Credentials.
http = httplib2.Http()
http = credentials.authorize(http)

# Build a service object for interacting with the API. Visit
# the Google Developers Console
# to get a developerKey for your own application.
service = build(serviceName='calendar', version='v3', http=http,
       developerKey='YOUR_DEVELOPER_KEY')
然后,我添加了以下代码以访问Google日历api(复制自):


不过,我需要在Google开发者控制台中提供两个ip地址,以使服务正常工作;即我的局域网ip(例如192.168.1.111)和我的当前IPv4地址(我通过搜索
我的ip地址是什么?
在谷歌上获得)。问题是,我的ISP不断更改分配给我的IP地址。因此,为了让我的测试应用程序正常工作,我必须去谷歌开发者控制台,在那里,
我的项目>>API&Auth>>凭证>>公共API访问
我必须修改允许的IP列表。为方便起见,我已将LAN ip设置为静态。但是,我无法控制ISP分配给我的IP地址。如何配置一个使用我的笔记本电脑作为服务器并能够通过更改的IP地址进行身份验证的服务?

它不仅允许您输入IP地址,还允许您输入子网。您的ISP将从一个池中分配您的公共地址,您可以在开发人员控制台中键入该池

例如,福特汽车公司的IP地址是19.0.0.1,但实际上它的IP地址不止这些,它的整个范围是19.0.0.0/8,换句话说,是19.0.0.0到19.255.255.255

您可以在允许的地址列表中输入19.0.0.1,也可以在整个范围内输入19.0.0.0/8

您的宽带调制解调器或网关很可能从ISP处获得DHCP租约。DHCP租约包括网络掩码信息。从网络掩码信息,您可以派生子网


不,在未注册应用程序的情况下,您无法访问任何Google API。我对python的了解还不够,但我很惊讶您不能像使用php进行测试那样将其设置为localhost。
page_token = None
while True:
  events = service.events().list(calendarId='primary', pageToken=page_token).execute()
  for event in events['items']:
    print event['summary']
  page_token = events.get('nextPageToken')
  if not page_token:
    break