You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Facebook pass_thread_control接口遇Invalid OAuth access token错误求助

Fixing the "Invalid OAuth access token" Error in Facebook Graph API pass_thread_control Call

Hey there, let's break down why you're hitting that OAuthException (code 190) error and how to fix it.

First, the most obvious issue in your code is how you're handling the accesstoken variable:

  • You defined it as a dictionary: accesstoken = { "access_token": "######"}
  • Then you tried to plug this directly into the URL string with .format(accesstoken). This means your final URL will have access_token={'access_token': '######'} instead of just the raw token string. Facebook's API can't parse that messy format, hence the invalid token error.

Step-by-step fixes:

  1. Correct the access token variable type
    Change your accesstoken to store just the token string, not a dictionary:

    accesstoken = "######"  # Replace with your actual valid access token
    
  2. Use a safer way to pass the access token
    Instead of error-prone string formatting, use requests' built-in params parameter to pass the token. This handles URL encoding automatically and keeps your code cleaner:

    import json
    import requests
    
    passData = json.dumps({
        "recipient": {"id": 627531511140634},
        "target_app_id": 123456789,
        "metadata": "-X pass_thread_control X-"
    })
    accesstoken = "######"
    passHeaders = {"Content-Type": "application/json"}
    
    hj = requests.post(
        "https://graph.facebook.com/v18.0/me/pass_thread_control",  # Use a recent API version
        headers=passHeaders,
        data=passData,
        params={"access_token": accesstoken}
    )
    
    # Print the full response to debug further if needed
    print(hj.json())
    
  3. Verify other critical details

    • API Version: You're using v2.6, which is extremely outdated. Facebook regularly deprecates old API versions, so switch to a recent stable version (like v18.0 at the time of writing) to avoid compatibility issues.
    • Token Validity: Ensure your access token is a valid Page Access Token with the pages_messaging permission. You can check its validity using Facebook's built-in Access Token Debugger tool.
    • Parameter Accuracy: Double-check that recipient.id is a valid Page-Scoped ID (PSID) of the user, and target_app_id is the correct ID of the app you're transferring thread control to.

If you fix the access token handling first and still get errors, checking the full response body (like we did with print(hj.json())) will give you more specific clues about what's wrong.

内容的提问来源于stack exchange,提问作者jehanzaib

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 10:07:54