如何在使用API Key时开启账户信息访问权限?Django示例权限咨询
Hey there! Since both your questions revolve around getting access to account-level data via the Evernote API, let's tackle them together step by step:
1. Enabling Account Info Access for Your API Key
To grant your app permission to pull account details like bandwidth limits or billing cycle dates, you need to configure this in the Evernote Developer Console:
- Log into your Evernote developer account and navigate to your registered application.
- Look for the Permissions section (usually under "App Settings" or "API Configuration").
- Find and enable the specific permission for account information—this is typically labeled
account_info(Evernote's API scopes use this identifier for accessing user account metadata). - Save your changes. Note that updating permissions might require you to re-authenticate any existing users, since their previous grants won't include the new scope.
2. Requesting Account Info Permissions in the Django Example
The Evernote Python SDK's Django sample uses OAuth for authorization, so you'll need to explicitly include the account_info scope when generating the authorization URL. Here's how to adjust the code:
- Locate the part of the Django view where you create the Evernote OAuth client or generate the authorization redirect.
- When setting the
scopeparameter, addaccount_infoto the existing scope list. For example, if the original code uses:
Update it to:scope = "basic"scope = "basic,account_info" - When users are redirected to the Evernote authorization page, they'll now see your app requesting access to their account information alongside any other scopes you've enabled.
- Once the user authorizes your app, you can use the Evernote
UserStoreAPI to fetch the account details you need. For example:from evernote.api.client import EvernoteClient client = EvernoteClient(token=user_auth_token, sandbox=True) user_store = client.get_user_store() user = user_store.getUser() # Access account details like remaining bandwidth remaining_bandwidth = user.remainingBandwidth cycle_start = user.billingCycleStart
Just a quick note: Make sure you're using the correct environment (sandbox vs production) in your client setup, as permissions and API endpoints can differ between the two.
内容的提问来源于stack exchange,提问作者user7433432

