我尝试使用github api为回购邮件加注星标:
curl -X PUT -H "Authorization: token *****************" https://api.github.com/user/starred/fulldecent/system-bus-radio
但响应总是
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}
我也尝试alamofire
Alamofire.request(.PUT, "https://api.github.com/user/starred/"+repoFullName, headers: ["Authorization": "token \(token)"]).responseJSON{ response in
......
}
但我仍然无法完成它
答案 0 :(得分:0)
有几个原因导致您出现404“未找到”错误。
第一个原因当然是您尝试使用的端点不存在,但是从docs开始,您似乎正确使用它。
此外,即使出现授权错误,GitHub API也会返回404,而不是像预期的那样返回403(请参阅documentation)。 您尝试使用的令牌可能无效,或者用户无权访问该存储库,或者令牌与用户不匹配,或者任何其他可能的授权问题。
答案 1 :(得分:0)
如果要使用put,则需要在授权时授予repo
范围的权限。
例如,当使用oauth github时。
步骤1: Create your oauth github app
步骤2:
您获得了client_id,将此源链接放在您的应用中,以便用户从github进行oauth
https://github.com/login/oauth/authorize?scope=user:email&client_id=<client_id>&scope=repo
第三步:
调用callBackUrl时,请按照以下步骤获取访问令牌
https://developer.github.com/v3/guides/basics-of-authentication/#providing-a-callback
最后一步: 您可以通过传递?access_token = xxxxxxxxxx
来加注星标