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

在RStudio中调用fbOAuth时遇“不安全登录被阻止”错误求助

Fixing "Unsafe Login Blocked" Error in RStudio for Facebook OAuth

Hey there! Let’s figure out how to fix that "不安全登录被阻止:无法从不安全页面获取访问令牌或登录此应用。请尝试以https://重新加载页面" error you’re hitting when using fbOAuth in RStudio.

Why This Happens

Facebook’s OAuth 2.0 security policies now require all authentication requests to use HTTPS instead of HTTP. Since RStudio’s default local server uses HTTP, Facebook blocks the request to protect your app and user data.

Step-by-Step Solutions

1. Update Your R Packages First

Make sure you’re using the latest version of the Rfacebook package (or any Facebook-related package you’re working with), as older versions might not support Facebook’s current HTTPS requirements. Run this in RStudio:

install.packages("Rfacebook")
library(Rfacebook)

2. Enable HTTPS in RStudio & Adjust Your fbOAuth Call

RStudio can run over HTTPS—here’s how to set it up and tweak your code:

  • Open RStudio’s settings (Tools > Global Options > Security)
  • Check the box for "Use HTTPS for RStudio Server" and restart RStudio
  • Update your fbOAuth call to use an HTTPS redirect URI:
appID <- "My app ID"
appSecret <- "My app secret"

fb_oauth <- fbOAuth(
  app_id = appID, 
  app_secret = appSecret, 
  extended_permissions = TRUE,
  redirect_uri = "https://localhost:8787/"  # Matches RStudio's default HTTPS port
)

3. Alternative: Use httr for More Flexible OAuth Handling

If Rfacebook’s fbOAuth still gives you trouble, the httr package offers greater control over HTTPS-based OAuth flows. Try this code:

library(httr)

# Set up your Facebook app details
fb_app <- oauth_app(
  appname = "YourAppName",
  key = appID,
  secret = appSecret
)

# Define Facebook's OAuth endpoints (using the latest API version)
fb_endpoint <- oauth_endpoint(
  authorize = "https://www.facebook.com/v18.0/dialog/oauth",
  access = "https://graph.facebook.com/v18.0/oauth/access_token"
)

# Fetch the access token with HTTPS redirect
fb_token <- oauth2.0_token(
  endpoint = fb_endpoint,
  app = fb_app,
  scope = "public_profile,email",  # Add any extended permissions you need
  redirect_uri = "https://localhost:8787/"
)

# Test the token with a simple API call
GET("https://graph.facebook.com/v18.0/me", config(token = fb_token))

4. Double-Check Your Facebook App Settings

Head over to the Facebook Developer Portal for your app and verify these details:

  • Your app is set to "Development Mode" (if you’re testing locally)
  • You’ve added the HTTPS redirect URI (https://localhost:8787/) to the "Valid OAuth Redirect URIs" list under Settings > Basic
  • Any extended permissions you’re requesting are enabled in App Review (if your app is public-facing)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 06:31:04