代码拉取完成,页面将自动刷新
使用 API 创建 Pull Request 失敗 出現 {"message":"401 Unauthorized"}
access_token 是利用 client-oauth2 直接透過帳密登入的方式取得
export function getToken(options: {
username?: string,
password?: string,
access_token?: string,
clientId: string,
clientSecret: string,
accessTokenUri?: string,
}): Promise<ClientOAuth2.Token>
{
options.accessTokenUri = options.accessTokenUri || GITEE_ACCESS_TOKEN_URI;
let giteeAuth = new ClientOAuth2({
clientId: options.clientId,
clientSecret: options.clientSecret,
accessTokenUri: options.accessTokenUri,
});
if (options.access_token)
{
//return giteeAuth.jwt.getToken(options.access_token);
return Promise.resolve(giteeAuth.createToken(options.access_token, {
token_type: 'bearer',
}));
}
return giteeAuth.owner.getToken(options.username, options.password);
}
發送 api 請求也是透過這個模組來發送
查詢資料之類的 api 都能正常使用
但是 建立 PR 的部分 卻一直出現 {"message":"401 Unauthorized"}
{ url: 'https://gitee.com/api/v5/repos/目標帳號/倉庫/pulls',
method: 'POST',
body:
{ title: 'title777',
head: '來源帳號:master',
base: 'master',
body: 'body666' },
query: {},
headers: { Authorization: 'Bearer 取得的access_token' } }
目標是將來源分支 發送 PR 目標 repo 來進行合併
另外 如果是透過 https://gitee.com/api/v5/swagger#/postV5ReposOwnerRepoPulls
卻能正常發送 PR
應用的部分在建立時 權限有全部勾選
不過應用主頁 與 回傳地址 是 直接填寫 https://gitee.com 就是
但是因為是利用帳密的方式來取得 token 這點應該不影響才對
{"message":"401 Unauthorized"}
把 access_token 放到body里试试
{ url: 'https://gitee.com/api/v5/repos/目標帳號/倉庫/pulls',
method: 'POST',
body:
{ title: 'title777',
head: '來源帳號:master',
base: 'master',
body: 'body666',
access_token: <Bearer 取得的access_token>},
query: {},
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
已解決 原來取得 token 時 必須要指定 scope
而不能自動取得應用建立時設定的權限
登录 后才可以发表评论