Facebook authentication failing over shinyapps.io

93 views
Skip to first unread message

Sushanta Deb

unread,
May 20, 2016, 1:50:40 AM5/20/16
to ShinyApps Users
Hi,

I am trying to get my users authenticated through facebook in my app.  The functionality works perfectly when run locally but fails when run over shinyapps.io.

Details:


library(httr)
library(Rfacebook)
app <- oauth_app('facebook', appid, secret)
Sys.setenv("HTTR_SERVER_PORT" = "1410/")
tkn <- oauth2.0_token(
  oauth_endpoints('facebook'), app, scope = 'ads_management',
  type  = 'application/x-www-form-urlencoded', cache = FALSE)
tkn <- tkn$credentials$access_token
fbname <- getUsers("me", token=tkn)


Do I need to change the HTTR_SERVER_PORT from 1410/ to something else or do I need to change the settings of my App in https://developers.facebook.com/apps/

Appreciate your guidance.

Thank you
SD

Joshua Spiewak

unread,
May 20, 2016, 9:59:28 AM5/20/16
to ShinyApps Users
Hi Sushanta,

This code is trying to listen on port 1410 for a callback from Facebook servers.
We do not support listening on additional ports on shinyapps.io at this time.
You may need to generate the long lived token locally and then deploy it with your application.

Sushanta Deb

unread,
May 20, 2016, 10:36:22 AM5/20/16
to ShinyApps Users
In that case how would other users in my webapp be able to say share some content from my webapp into their timeline?

Joshua Spiewak

unread,
May 20, 2016, 10:50:35 AM5/20/16
to ShinyApps Users
"fbOAuth creates a long-lived OAuth access token that enables R to make authenticated calls to the Facebook API. The token can be saved as a file in disk to be re-used in future sessions."

You create the token that identifies your application to Facebook so your application can identify itself.
That token you would include in a file in your application.

You would not create this token for each user of your application. Instead, the users would need to grant your application permission to post on their timeline.

Sushanta Deb

unread,
May 20, 2016, 11:23:15 AM5/20/16
to ShinyApps Users
Excellent.  I will try this today and keep you posted

Sushanta Deb

unread,
May 20, 2016, 3:55:16 PM5/20/16
to ShinyApps Users
It did not yield the desired result.  Please please help me on this.  Below is the situation

In the local environment, I used the below per your suggestion and this works fine

  library(httr)
app <- oauth_app('facebook', appID, appsecret)
Sys.setenv("HTTR_SERVER_PORT" = "1410/")
fb_oauth <- oauth2.0_token(
  oauth_endpoints('facebook'), app, scope = 'ads_management',
  type  = 'application/x-www-form-urlencoded', cache = FALSE)
save(fb_oauth, file="fb_oauth")
load("fb_oauth")
tkn <- fb_oauth$credentials$access_token
fbname <- getUsers("me", token=tkn)
updateStatus("Hello World", token=tkn, link = "www.shinyapps.io")

Now in shinyapps.io I used the following:
load("fb_oauth")
tkn <- fb_oauth$credentials$access_token


fbname <- getUsers("me", token=tkn)

updateStatus(paste("Analysis by ",fbname$name," using www.gocharting.com",sep=""), token=tkn, link = capture)

2 observations when above is executed in shinyapps.io:
1. It posts the link in my facebook timeline even when someone else is logged into facebook in the browser.
2. It only posts once when post button in ui.R is clicked. Subsequent clicks do not post anything onto FB

Please let me know what I may be doing wrong here

SD

Reply all
Reply to author
Forward
0 new messages