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

如何通过Facebook主页URL或用户名获取用户ID?

How to Retrieve a Facebook User/Page ID from a Username or URL

Hey there, I totally get where you're coming from—this used to be a quick, no-fuss task, but Facebook has clamped down hard on API access for privacy reasons, which is exactly why that direct https://graph.facebook.com/username call is throwing the OAuthException #803 error you’re seeing. The post you came across is spot-on: Facebook no longer allows querying users directly by username via their public API.

That said, there are a few workarounds depending on whether you’re targeting a public Facebook Page or a personal profile:

Feasible Solutions

  • Extract ID from Embedded Page Plugins
    For public Facebook Pages, use Facebook’s Page Plugin to generate an embed for the page. When you create the embed code, the page ID will be hidden in either the data-href attribute or the accompanying JavaScript snippet. For example, the embed might include something like data-href="https://www.facebook.com/PageName/?ref=embed_page"—you can inspect the embedded content’s metadata to pull out the ID, or use the plugin’s JS to access page details (just make sure you follow Facebook’s embedding guidelines).

  • Scrape Public Page Metadata (Proceed With Caution)
    Public pages often include their ID in HTML meta tags. If you fetch the page’s source code, look for tags like:

    <meta property="fb:page_id" content="1234567890" />
    

    or

    <meta property="al:android:url" content="fb://page/1234567890" />
    

    A quick heads-up: Scraping Facebook’s pages might violate their Terms of Service, so only use this for personal, non-commercial purposes. Facebook actively blocks scraping tools, so this method could stop working at any time.

  • Use the Graph API with a Valid Access Token
    If you have a valid access token (either a user token with appropriate permissions or an app token), you can use the search endpoint to look up pages (personal profiles are far more restricted here). The request would look like:

    https://graph.facebook.com/v19.0/search?q=YOUR_USERNAME&type=page&access_token=YOUR_TOKEN
    

    For personal profiles, this only works if the user has set their profile to be searchable and your app has been granted rare, specific permissions (Facebook is extremely strict about accessing personal user data now). For pages, this is more feasible if your app meets their requirements.

  • Check URL Redirects
    Sometimes, visiting a username-based URL (like https://facebook.com/MyUsername) redirects to a URL that includes the ID, e.g., https://www.facebook.com/profile.php?id=1234567890. You can send a HEAD request to the username URL and check the Location header for this redirected link, then extract the ID from the id parameter. Note that this won’t work for profiles/pages with strict privacy settings that disable direct redirects.

Critical Reminders

  • Facebook’s policies and API restrictions change constantly—any workaround here could stop working overnight without warning.
  • Always follow Facebook’s Terms of Service. Unauthorized scraping or API misuse can result in your account or app being banned.
  • For personal user profiles, it’s increasingly hard to get the ID unless the user explicitly shares it with you, thanks to Facebook’s strict privacy controls.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 07:35:12