我有一个非常简单的应用程序,我从https://developers.google.com/google-apps/calendar/instantiate复制并粘贴在下面:
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(从https://developers.google.com/google-apps/calendar/v3/reference/events/list复制):
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
但是,我需要在Google开发人员控制台中提供两个IP地址才能使服务正常运行;即我的局域网IP(例如192.168.1.111)和我当前的IPv4地址(我在Google上搜索What is my IP address?
得到的)。问题是,我的ISP不断更改分配给我的IP地址。因此,要让我的测试应用程序工作,我必须转到Google开发人员的控制台,并在My Project>>APIs & Auth>>Credentials>>Public API access
我必须修改允许的IP列表。为方便起见,我使我的局域网IP静态。但是,我无法控制ISP分配给我的IP地址。如何配置使用笔记本电脑作为服务器并能够使用不断变化的IP地址进行身份验证的服务?
答案 0 :(得分:0)
它不仅可以让您输入IP地址,还可以输入子网。您的ISP将从池中分配您的公共地址,您可以在开发者控制台中键入该池。
例如,福特汽车公司的IP地址为19.0.0.1,但实际上它有更多,它的整个范围是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租约包括网络掩码信息。从网络掩码信息中,您可以派生您的子网。