ploner / RMixpanel

RMixpanel - Mixpanel API client package for R
Other
18 stars 6 forks source link

Issues with auth for https://mixpanel.com/ #6

Open clinderDemiurge opened 5 years ago

clinderDemiurge commented 5 years ago

Hello,

I can't seem to authenticate with any https://mixpanel.com/ endpoints. This includes segmentation and funnels. Based on the simple funnel example I tried the following:

This doesn't work - "object 'res' not found"

mixpanelGetData(account, method="funnels/list/", args=list(), data=TRUE)

This doesn't work either - "Unknown SSL protocol error in connection to mixpanel.com:443"

headers = c(Authorization = paste("Basic ", base64enc::base64encode(charToRaw(paste(account$apiSecret, ":", account$apiSecret, sep = ""))), sep = "")) url <- "https://mixpanel.com/api/2.0/funnels/list/?" RCurl::getURL(url, httpheader = headers)

Also doesn't work - "<?xml version='1.0' encoding='UTF-8'?>AuthenticationRequiredAuthentication required."

url <- "https://data.mixpanel.com/api/2.0/funnels/list/?" RCurl::getURL(url, httpheader = headers)

However the following does work:

url <- "https://data.mixpanel.com/api/2.0/export/?event=%5B%22Purchase3%22%5D&from_date=2018-10-01&to_date=2018-10-02&" RCurl::getURL(url, httpheader = headers)

myArgs <- list() myArgs$event <- "[\"Purchase3\"]" myArgs$from_date <- "2018-10-01" myArgs$to_date <- "2018-10-02" mixpanelGetData(account, method="export/", args=myArgs, data=TRUE)

Any idea what is going on? Thanks in advance.

clinderDemiurge commented 5 years ago

Hello again,

I'm not sure this is the best fix but I've found a work around by making a local change in mixpanelGetData replacing "RCurl" with "crul".

  # Not using RCurl because auth doesn't work for non-export endpoints
  # res <- RCurl::getURL(url, httpheader=headers, .encoding=encoding) # See fork https://github.com/jzking/RMixpanel.

  # Using crul instead of RCurl
  resHttp <- crul::HttpClient$new(
    url = url,
    auth = crul::auth(user = account$apiSecret, pwd = account$apiSecret)
  )
  x <- resHttp$get()
  res <- x$parse(encoding)