闪亮的谷歌登录

问题描述 投票:0回答:1

我想为我的闪亮应用程序实现谷歌登录,(我已经检查了这个问题,但它不再工作了,它似乎已被弃用)。我使用了here中的示例来代替:

library(shiny)
library(googleAuthR)
options(shiny.port = 1221)

options(googleAuthR.webapp.client_id = "someclientid.apps.googleusercontent.com")
    
ui <- fluidPage(
  
  titlePanel("Sample Google Sign-In"),
  
  sidebarLayout(
    sidebarPanel(
      googleSignInUI("demo")
    ),
    
    mainPanel(
      with(tags, dl(dt("Name"), dd(textOutput("g_name")),
                    dt("Email"), dd(textOutput("g_email")),
                    dt("Image"), dd(uiOutput("g_image")) ))
    )
  )
)

server <- function(input, output, session) {

  sign_ins <- shiny::callModule(googleSignIn, "demo")

  output$g_name = renderText({sign_ins()$name})
  output$g_email = renderText({ sign_ins()$email })
  output$g_image = renderUI({ img(src=sign_ins()$image) })
  
}

# Run the application 
shinyApp(ui = ui, server = server)

但是当我用我的帐户登录时,没有任何反应:

这是登录前的样子:

这是登录后的弹窗:

最后又回到这里(和开头一样):

我希望用户信息出现在

Name
Email
Image
旁边。不确定我是否错过了什么。有什么建议吗?

r shiny google-oauth google-signin googleauthr
1个回答
0
投票

这是一个迟到的答案,但希望可以帮助其他人!我怀疑问题出在您设置客户端 ID 的 google 项目设置上。 我几年前就用过这个方法。现在我重新访问并注意到很多东西已经特别更新了 googleAuthR,但概念是相同的。这是我刚刚测试过的第二个链接中的相同代码,并且工作正常。 确保在 Google API 项目的

Authorized JavaScript origins
Authorized redirect URIs 部分中设置 http://localhost:yourPort

此外,fedCMmigrate 也值得关注,因为它将从 2024 年开始取代 thier-party-cookies。

options("googleAuthR.webapp.client_id" = "xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com")
options("googleAuthR.webapp.client_secret" = "xxxxxxxxxxxxxxxxxxxxxxxx")
options("googleAuthR.scopes.selected" = c("https://www.googleapis.com/auth/userinfo.email", 
                                          "https://www.googleapis.com/auth/userinfo.profile", 
                                          "https://www.googleapis.com/auth/cloud-platform"))
options("googleAuthR.redirect" = "storagerelay://http/localhost:yourPort?id=xxxxxx")

app <- shinyApp(
  ui = fluidPage(
    
    titlePanel("Sample Google Sign-In"),
    
    sidebarLayout(
      sidebarPanel(
        googleSignInUI("demo")
      ),
      
      mainPanel(
        with(tags, dl(dt("Name"), dd(textOutput("g_name")),
                      dt("Email"), dd(textOutput("g_email")),
                      dt("Image"), dd(uiOutput("g_image")) ))
      )
    )
  ), 
  
  server = function(input, output, session) {
    
    sign_ins <- shiny::callModule(googleSignIn, "demo")
    
    output$g_name = renderText({ sign_ins()$name })
    output$g_email = renderText({ sign_ins()$email })
    output$g_image = renderUI({ img(src=sign_ins()$image) })
    
  })

# Run the application. 
# This way you can specify your defined port in your project.
runApp(app, port = yourPort)
© www.soinside.com 2019 - 2024. All rights reserved.