New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable too run LinkedIn demo due to environment lock #113

Closed
dempseydata opened this Issue Jul 4, 2014 · 22 comments

Comments

Projects
None yet
5 participants
@dempseydata

dempseydata commented Jul 4, 2014

I receive the following message when trying to run the linked in demo:

Error in assign(mname, def, where) :
cannot add bindings to a locked environment

@hadley

This comment has been minimized.

Member

hadley commented Jul 4, 2014

How are you running it? And when do you get the error?

@dempseydata

This comment has been minimized.

dempseydata commented Jul 4, 2014

RStudio, mac OS Mavericks, R 3.0.3, httr 0.3 both with a copy and paste of the demo from github and altering for my keys, as well as from the RStudio command line with:

demo(package='httr', topic='oauth2-linkedin')

@dempseydata

This comment has been minimized.

dempseydata commented Jul 4, 2014

I'm guessing I have an underlying issue affecting other things too, as the twitter demo code fails too when I add in my keys. Specifically:
twitter_token <- oauth1.0_token(oauth_endpoints("twitter"), myapp)
gives me:
Error in init_oauth1.0(endpoint, app, permission = params$permission) :
client error: (401) Unauthorized

@dempseydata

This comment has been minimized.

dempseydata commented Jul 4, 2014

R 3.1.0 also has the same issues

@dempseydata

This comment has been minimized.

dempseydata commented Jul 4, 2014

@siddharthab

This comment has been minimized.

Contributor

siddharthab commented Jul 16, 2014

I am also seeing the same error. This link seems to suggest that package namespaces are locked and therefore new bindings can not be created in them. I guess this is new behavior from R 3.0.2.
"The namespace environments of packages with namespaces are locked when loaded."
http://stat.ethz.ch/R-manual/R-devel/library/base/html/bindenv.html

For reference classes, even removing the 'where' argument and using the following statement does not work, as it fails to find the non-exported functions. The same technique however works for closures in general. So I am not sure what is happening with reference classes.

environment(TokenLinkedIn) <- asNamespace("httr")

This is sad because this makes extending reference classes from other packages impossible in any meaningful way. Only if all the symbols that the reference class uses is exported from the package namespace, can one extend the reference class in his own environment and then use it.

@hadley

This comment has been minimized.

Member

hadley commented Jul 16, 2014

@siddharthab Yes, that's my interpretation too. This is one reason that we (Rstudio) are thinking about moving away from reference classes. (cc @ramnathv)

@dempseydata

This comment has been minimized.

dempseydata commented Jul 16, 2014

Thank you Siddhartha and Hadley. I guess I will downgrade my R version for the time being, and wait patiently for httr to be reworked for newer versions.

--- sent from iPhone ---

On Jul 16, 2014, at 15:51, Hadley Wickham notifications@github.com wrote:

@siddharthab Yes, that's my interpretation too. This is one reason that we (Rstudio) are thinking about moving away from reference classes. (cc @ramnathv)


Reply to this email directly or view it on GitHub.

@siddharthab

This comment has been minimized.

Contributor

siddharthab commented Jul 16, 2014

If you don't need caching for your LinkedIn tokens, you can override the caching methods (cache and load_from_cache) in the reference class to be no-ops or have your own implementation. Then, if you remove the where clause, the demo will work fine. This is what I am doing for service account tokens for Google, but there I genuinely don't need caching.

@dempseydata

This comment has been minimized.

dempseydata commented Jul 17, 2014

My coding is not that good, this is my learning project! Would you be willing to share example workaround code?

I might just downgrade anyway, I have a similar issue with the twitter demo! I assume it is the same root cause

--- sent from iPhone ---

On Jul 16, 2014, at 16:30, Siddhartha Bagaria notifications@github.com wrote:

If you don't need caching for your LinkedIn tokens, you can override the caching methods (cache and load_from_cache) in the reference class to be no-ops or have your own implementation. Then, if you remove the where clause, the demo will work fine. This is what I am doing for service account tokens for Google, but there I genuinely don't need caching.


Reply to this email directly or view it on GitHub.

@siddharthab

This comment has been minimized.

Contributor

siddharthab commented Jul 17, 2014

This is the hack. First remove the where argument in the class def and set cache to FALSE when creating the token. See if that works.

token <- new_token(TokenLinkedIn, oauth_endpoints("linkedin"), myapp, cache=FALSE)

If it does not, then also change the class def to this:

TokenLinkedIn <- setRefClass("TokenLinkedIn", contains = "Token2.0",
    methods = list(
        sign = function(method, url) {
            url <- parse_url(url)
            url$query$oauth2_access_token <- credentials$access_token
            list(url = build_url(url), config = config())
        },
        cache = function() {
            .self ## No-op
        },
        load_from_cache = function() {
            FALSE
        }
    )
)
@siddharthab

This comment has been minimized.

Contributor

siddharthab commented Jul 17, 2014

I see that the refresh function has cache instead of .self$cache which might cause problems later when the token needs to be refreshed.

@dempseydata

This comment has been minimized.

dempseydata commented Jul 21, 2014

The function rewrite works, however, a redirect url needs to be defined in the app of: http://locasthost:1410/

Otherwise you receive an error message due to a bad redirect. @hadley I could not see a way in the httr functions, to specify the redirect correctly.

@statguy

This comment has been minimized.

statguy commented Aug 21, 2014

One way to go around the locking: http://stackoverflow.com/a/25399078/3959140

@joelgombin

This comment has been minimized.

joelgombin commented Oct 5, 2014

Hello, I have the same error but when trying to get a twitter token. Any idea how to fix that issue without downgrading the R version?

@dempseydata

This comment has been minimized.

dempseydata commented Oct 5, 2014

I expect the same code tweak for linkedin example would work

--- sent from iPhone ---

On Oct 5, 2014, at 11:12, Joel Gombin notifications@github.com wrote:

Hello, I have the same error but when trying to get a twitter token. Any idea how to fix that issue without downgrading the R version?


Reply to this email directly or view it on GitHub.

@joelgombin

This comment has been minimized.

joelgombin commented Oct 5, 2014

Except that there is no class definition nor new_token line for twitter auth...

@siddharthab

This comment has been minimized.

Contributor

siddharthab commented Oct 5, 2014

You should not get this error at all for the twitter demo as you are not extending the Reference class in that demo. Would you mind posting a log of your attempt and possibly even sessionInfo?

I am assuming we are talking about the oauth1 example. If you are using oauth2, then replacing the endpoints in the LinkedIn example with those for twitter, and using the mod in this thread should work.

@joelgombin

This comment has been minimized.

joelgombin commented Oct 5, 2014

I get the 401 error when trying to replicate the twitter demo. The only difference is that i pass the secret through the call to oauth_app.

Here is the log:

> oauth_endpoints("twitter")
<oauth_endpoint>
 request:   https://api.twitter.com/oauth/request_token
 authorize: https://api.twitter.com/oauth/authenticate
 access:    https://api.twitter.com/oauth/access_token
> myapp <- oauth_app("twitter", key = "XXXXXXXXXXXX", secret = "XXXXXXXXXXXXXXXXXXXXXXX")
> twitter_token <- oauth1.0_token(oauth_endpoints("twitter"), myapp)
Use a local file to cache OAuth access credentials between R sessions?
1: Yes
2: No

Selection: Yes
Error in init_oauth1.0(endpoint, app, permission = params$permission) : 
  client error: (401) Unauthorized

and here is my session info:

> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C            LC_COLLATE=C         LC_MONETARY=C       
 [6] LC_MESSAGES=C        LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C         LC_TELEPHONE=C      
[11] LC_MEASUREMENT=C     LC_IDENTIFICATION=C 

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] httr_0.5.0.9000  shiny_0.10.2.1   ggvis_0.3.0.9003 scales_0.2.4     ggplot2_1.0.0    devtools_1.6     doParallel_1.0.8
 [8] iterators_1.0.7  foreach_1.4.2    lubridate_1.3.3  dplyr_0.3        RMySQL_0.9-3     DBI_0.3.1       

loaded via a namespace (and not attached):
 [1] MASS_7.3-34      R6_2.0           RCurl_1.95-4.3   RJSONIO_1.3-0    Rcpp_0.11.3      assertthat_0.1   codetools_0.2-9 
 [8] colorspace_1.2-4 digest_0.6.4     evaluate_0.5.5   formatR_1.0      grid_3.1.1       gtable_0.1.2     htmltools_0.2.6 
[15] httpuv_1.3.0     knitr_1.6        magrittr_1.0.1   mime_0.2         munsell_0.4.2    plyr_1.8.1       proto_0.3-10    
[22] reshape2_1.4     rmarkdown_0.3.3  stringr_0.6.2    tools_3.1.1      xtable_1.7-3     yaml_2.1.13     
@siddharthab

This comment has been minimized.

Contributor

siddharthab commented Oct 6, 2014

This is an unrelated error. Probably Twitter's APIs have changed since the last time this demo was successfully run. It does not work for me either. Please open another issue in this project. In the meanwhile, you might have more luck with the twitteR package.

@joelgombin

This comment has been minimized.

joelgombin commented Oct 6, 2014

twitteR package is fine but I want to use a twitter functionality not implemented in twitteR (namely, embedding tweets) which, unfortunately, requires to be authentified. I tried to use twitteR authentification for that but didn't manage; I may have missed something there, though.

@hadley hadley closed this in 055d4a7 Oct 6, 2014

@hadley

This comment has been minimized.

Member

hadley commented Oct 6, 2014

I think it's impossible to work around this using RC, so I've switch to R6. The code is very similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment