我正在使用mediawiki api上传文件。我正在发送一个多部分POST请求到
https://commons.wikimedia.org/w/api.php?format=json&action=upload&filename=xxx
在头中我包括我的Autherzation: Bearer accessToken123
,在正文中我包括我的CSRF令牌,以及我的多部分文件,所有这些都按照文档。
但是,我从服务器得到的响应如下:
{
"error": {
"code": "permissiondenied",
"info": "The action you have requested is limited to users in one of the groups: *, [[Commons:Users|Users]].",
"*": "See https://commons.wikimedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes."
},
"servedby": "mw1448"
}
这是不言自明的,但是当我用
检查我的权限/组时https://commons.wikimedia.org/w/rest.php/oauth2/resource/profile
得到如下结果:
{"sub":xxxx,"username":"xxxxx","editcount":7,"confirmed_email":true,"blocked":false,"registered":"xxxx",
"groups":["*","user","autoconfirmed"],
"rights":["read","writeapi","viewmyprivateinfo","abusefilter-view","abusefilter-log","upload","upload_by_url","reupload-own","purge","reupload","autoconfirmed","editsemiprotected","skipcaptcha","abusefilter-log-detail","transcode-reset"],
"grants":["basic","uploadfile","uploadeditmovefile","privateinfo"],"realname":"","email":"xxxx"}
正如你所看到的,我既是所需组的一部分,也有必要的upload
权利。错误信息非常清楚,所以我不知道我错过了什么。它不是CSRF令牌或访问令牌,提供这些错误会导致不同的错误消息。如有任何帮助,不胜感激。
我终于明白了:当从mediawiki请求应用密钥时,你可以选择应用代表用户拥有的权利。如果您想将图片上传到维基共享资源,您不仅需要">
">与媒体互动:上传新文件;上传、替换和移动文件
右,还有
创建、编辑和移动页面
正确,因为每次上传都创建了一个新页面。我希望这对将来的其他人有所帮助:')