[我正在尝试使用Box API,我已经设置了本地SDK,授权了API令牌,我认为我基本上是正确的,我唯一的问题是开发者的toke(这是一个.JSON文件, ht桌面似乎可以正常工作,我在做什么错?
from boxsdk import OAuth2, Client
oauth = OAuth2(
client_id='s2dfw23wer3s6b1t4grd5grv', #don't worry these are fake
client_secret='pHgPObYY2342f2f3HIHVvPOb', #don't worry these are fake
access_token='YOUR_DEVELOPER_TOKEN', #currently im just using the root path is that wrong
)
client = Client(oauth)
root_folder = client.folder(folder_id='0')
shared_folder = root_folder.create_subfolder('NEW FOLDER')
shared_link = shared_folder.get_shared_link()
[无论何时将访问令牌传递给API,它都必须是物理令牌。如果令牌是静态的,通常使用配置文件来实现,您只需要从文件中读取令牌即可。说文件看起来像这样:
# mytoken.json
{
"token": "kdvnajdfhaoejfskjvnb",
}
您将以这种方式加载它:
from boxsdk import OAuth2, Client
import json
def load_token_from_file(token_path):
with open(token_path) as fh:
# get your token from the token key
token = json.load(fh)['token']
oauth = OAuth2(
client_id='s2dfw23wer3s6b1t4grd5grv', #don't worry these are fake
client_secret='pHgPObYY2342f2f3HIHVvPOb', #don't worry these are fake
access_token=load_token_from_path('path/to/token.json'), # now you're getting the token from the file itself
)