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

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

代码还原动作

export const addComment = (id, text) => async (dispatch, getState) => 
{

    try {
        const obj = {
            snippet: {
                videoId: id,
                topLevelComment: {
                    snippet: {
                        textOriginal: text,
                        videoId: id,
                    }
                }
            }
        }
        await request.post('/commentThreads', obj, {
            params: {
                part: 'id, replies, snippet',
                videoId: id,
            },
            headers: {
                'Content-Type': 'application/json',
                Authorization: `Bearer ${getState().auth.accessToken}`,
            }
        })
        dispatch({
            type: CREATE_COMMENT_SUCCESS,
        })
        setTimeout(() => dispatch(getCommentVideoById(id)), 2000)

    } catch (error) {
        console.log(error.message);
        dispatch({
            type: CREATE_COMMENT_FAIL,
            payload: error.message
        })
    }
 }

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

pvcm50d1

pvcm50d11#

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

相关问题