2017-10-14 76 views
0

我是一個優步的驅動程序,我正在開發一個python代碼來檢索API優步的驅動程序歷史。我所看到的文檔和我有這個第一代碼寫入第一步AUTH:優步API無效範圍錯誤使用python

from uber_rides.auth import AuthorizationCodeGrant 
auth_flow = AuthorizationCodeGrant(
'my_client_id', 
'partner.trips', 
'my_secret_client', 
'http://localhost:8000' 
) 
auth_url = auth_flow.get_authorization_url().replace('+','') 
print(auth_url) 

的範圍,我沒有設定partner.trips該文檔說,如果你使用這個端點以檢索車次:

https://api.uber.com/v1/partners/trips 

當我運行的代碼,這是URL結果:

https://login.uber.com/oauth/v2/authorize?scope=partner.trips&state=a22YiIePVScRMh12gLbgZFnDK6415HHG&redirect_uri=http%3A%2F%2Flocalhost%3A8000&response_type=code&client_id=my_client_id 

但是當我把網址到瀏覽器我recive這個錯誤:

http://localhost:8000/?error=invalid_scope&state=iyzAM1rPWnZDFHqJlXEViTUL3UsLIz2O#_ 

錯誤無效範圍。我已經看到我的開發人員dashbord,我沒有這個範圍,但我有範圍歷史。因此,如果設置歷史範圍我收到的代碼爲重定向URL,但如果我用這個代碼來生成令牌,使用令牌調用此終點:

https://api.uber.com/v1/partners/trips 

我recive這個錯誤:

{"message":"This endpoint requires at least one of the following scopes: partner.trips, partner.admin_trips.locations, partner.admin_trips","code":"unauthorized"} 

請幫忙嗎?我正在變得瘋狂。

回答

0

這聽起來像你沒有合作伙伴.trips範圍:
「我看到了我的開發人員儀表板,我沒有這個範圍。」

當你沒有這個範圍,因此您收到的錯誤信息是正確的:

{「消息」:「此端點需要以下範圍的至少一個:partner.trips,partner.admin_trips .locations,partner.admin_trips「,」code「:」未授權「}

輸入歷史記錄範圍不會讓您訪問驅動程序API partner.trips scope。您可以通過https://developer.uber.com/products/drivers申請驅動程序API訪問權限(目前有限)。