我目前正在测试Google Search Console API和Flask Dance来执行oauth的工作。
它非常适合获取/ sites,但我得到了
ValueError:View函数未返回响应
如果我尝试使用/ search
查询searchAnalytics根据https://developers.google.com/webmaster-tools/search-console-api-original/v3/searchanalytics/query#try-it,它必须是POST +附加数据。 e.g:
json={'startDate':'2017-11-01','endDate':'2017-12-01'}
在https://developers.google.com/oauthplayground/中,它的工作方式与此类似,但烧瓶的舞蹈可悲。任何想法?
import os
from werkzeug.contrib.fixers import ProxyFix
from flask import Flask, redirect, url_for
from flask_dance.contrib.google import make_google_blueprint, google
from raven.contrib.flask import Sentry
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)
sentry = Sentry(app)
app.secret_key = os.environ.get("FLASK_SECRET_KEY", "supersekrit")
app.config["GOOGLE_OAUTH_CLIENT_ID"] = os.environ.get("GOOGLE_OAUTH_CLIENT_ID")
app.config["GOOGLE_OAUTH_CLIENT_SECRET"] = os.environ.get("GOOGLE_OAUTH_CLIENT_SECRET")
google_bp = make_google_blueprint(scope=["profile", "email", "https://www.googleapis.com/auth/webmasters"])
app.register_blueprint(google_bp, url_prefix="/login")
@app.route("/")
def index():
return "BlA BLA"
@app.route("/sites")
def sites():
if not google.authorized:
return redirect(url_for("google.login"))
resp = google.get("/webmasters/v3/sites")
siteEntry = resp.json()["siteEntry"]
result = ""
for site in siteEntry:
result = result + site["siteUrl"] + "</br>"
return result
@app.route("/search")
def search():
if not google.authorized:
return redirect(url_for("google.login"))
resp = google.post("/webmasters/v3/sites/https%3A%2F%2Fzrce.eu/searchAnalytics/query", json={'startDate':'2017-11-01','endDate':'2017-12-01'})
print(resp)
if __name__ == "__main__":
app.run()
答案 0 :(得分:0)
所有API路由都应该返回一些东西,即使它是一个空响应。
只需返回回复即可,""
或resp
。