redux 我正在克隆youtube到评论帖子,但我得到了一个错误请求失败,状态代码为401

wwwo4jvm  于 2023-08-05  发布在  其他
关注(0)|答案(1)|浏览(191)

代码还原动作

  1. export const addComment = (id, text) => async (dispatch, getState) =>
  2. {
  3. try {
  4. const obj = {
  5. snippet: {
  6. videoId: id,
  7. topLevelComment: {
  8. snippet: {
  9. textOriginal: text,
  10. videoId: id,
  11. }
  12. }
  13. }
  14. }
  15. await request.post('/commentThreads', obj, {
  16. params: {
  17. part: 'id, replies, snippet',
  18. videoId: id,
  19. },
  20. headers: {
  21. 'Content-Type': 'application/json',
  22. Authorization: `Bearer ${getState().auth.accessToken}`,
  23. }
  24. })
  25. dispatch({
  26. type: CREATE_COMMENT_SUCCESS,
  27. })
  28. setTimeout(() => dispatch(getCommentVideoById(id)), 2000)
  29. } catch (error) {
  30. console.log(error.message);
  31. dispatch({
  32. type: CREATE_COMMENT_FAIL,
  33. payload: error.message
  34. })
  35. }
  36. }

字符串
When I click on the network error, it shows
code component comment
在这种情况下,有什么方法可以帮助我吗?
我不能发表评论,我已经从API加载了评论列表并获得了id,我不知道为什么,因为我是api的新手

pvcm50d1

pvcm50d11#

检查您是否在响应中正确添加了访问令牌。
错误401表示Unauthorized

相关问题