Closed devktpx closed 6 years ago
I'm not aware of such limitation in fbRads
, it should work with any valid token. Can you share your devtools::session_info()
output?
Thanks for the quick reaction. I sent you my sessioninfo via mail.
It is line 2 of the error message that especially strikes me:
ERROR [2018-08-02 10:36:40] URL: https://graph.facebook.com/v3.1/act_XXXXXXXXXXXX/
Shouldn't the url be (a) https://graph.facebook.com/v3.1/act_XXXXXXXXXXXXXX?access_token=YYYYYYYYYYYYYYYY
rather than (b) https://graph.facebook.com/v3.1/act_XXXXXXXXXXXX/
? (a) works fine when called in the browser, (b) does not.
The URL is fine, the access_token
param for the GET
request is set later. Run debugonce(fbRads:::fbad_request)
and then your fbad_init
call to see from line to line what happens there.
I did this. But it just seems to return the definition of the debug-function. Am I doing it right?
Here is the script:
library(fbRads)
debugonce(fbRads:::fbad_request)
fbad_init(accountid=XXXXXXX, token="YYYYYYY", version = "3.1")
Here is the output:
TRACE [2018-08-02 11:58:07] Initializing connection to account XXXXXXXXXXXX via API v3.1
debugging in: fbad_request(path = paste0("act_", accountid, "/"), method = "GET",
params = list(access_token = token, fields = scope), version = version)
debug: {
mc <- match.call()
method <- match.arg(method)
if (is.null(params$access_token)) {
if (missing(fbacc)) {
params$access_token <- getFromNamespace("fbacc",
"fbRads")$access_token
}
else {
params$access_token <- fbad_check_fbacc(fbacc)$access_token
}
}
if (missing(version)) {
if (missing(fbacc)) {
if (is.FB_Ad_Account(getFromNamespace("fbacc", "fbRads"))) {
version <- getFromNamespace("fbacc", "fbRads")$api_version
}
else {
version <- fb_api_most_recent_version()
}
}
else {
version <- fbad_check_fbacc(fbacc)$api_version
}
}
params <- fbad_check_curl_params(params)
b = basicTextGatherer(.mapUnicode = FALSE)
h = basicHeaderGatherer()
if (debug) {
print(params)
}
path <- sub(paste0("^https://graph.facebook.com/v", version,
"/"), "", path)
API_endpoint <- paste("https://graph.facebook.com", paste0("v",
version), path, sep = "/")
if (method == "DELETE") {
curlres <- tryCatch(res <- getURLContent(url = paste0(API_endpoint,
"?", paste(mapply(function(id, v) paste(URLencode(id),
URLencode(v), sep = "="), names(params), params),
collapse = "&")), .opts = curlOptions(headerfunction = h$update,
verbose = debug, writefunc = b$update, customrequest = "DELETE",
cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"),
connecttimeout = 3, timeout = 300)), error = function(e) e)
}
else {
curlres <- tryCatch(res <- do.call(what = paste0(ifelse(method ==
"GET", "get", "post"), "Form"), args = list(uri = API_endpoint,
.params = params, .opts = curlOptions(headerfunction = h$update,
verbose = debug, writefunc = b$update, cainfo = system.file("CurlSSL",
"cacert.pem", package = "RCurl"), crlf = ifelse(method ==
"GET", TRUE, FALSE), connecttimeout = 3, timeout = 300))),
error = function(e) e)
}
params$token <- params$access_token <- NULL
if (inherits(curlres, "error")) {
if (grepl("Network is unreachable", curlres$message) |
grepl("Empty reply from server", curlres$message) |
grepl("Failed to connect to graph.facebook.com",
curlres$message) | grepl("(Connection|Operation) timed out after",
curlres$message) | grepl("Unknown SSL protocol error",
curlres$message) | grepl("OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to graph.facebook.com",
curlres$message) | grepl("OpenSSL SSL_read: SSL_ERROR_SYSCALL",
curlres$message)) {
flog.error(paste("Possible network error:", curlres$message),
name = "fbRads")
flog.info(paste("Retrying query for the", retries +
1, " st/nd/rd time"), name = "fbRads")
Sys.sleep(2)
if (retries < 3) {
mc$retries <- retries + 1
return(eval(mc, envir = parent.frame()))
}
}
res <- curlres
}
if (inherits(res, "error")) {
if (log) {
flog.error(paste("URL: ", API_endpoint), name = "fbRads")
flog.error(paste("Method: ", method), name = "fbRads")
flog.error(paste("Params: ", paste(capture.output(str(params)),
collapse = "\n")), name = "fbRads")
}
stop(paste(ifelse(inherits(curlres, "error"), "This is a bug in the fbRads package. Please report on GitHub with a detailed output:",
"FB query failed:"), res$message))
}
res <- b$value()
headers <- as.list(h$value())
if (headers$status != "200") {
if (log) {
flog.error(paste("URL: ", API_endpoint), name = "fbRads")
flog.error(paste("Method: ", method), name = "fbRads")
flog.error(paste("Params: ", paste(capture.output(str(params)),
collapse = "\n")), name = "fbRads")
flog.error(paste("Header:", toJSON(headers)), name = "fbRads")
flog.error(paste("Body:", res), name = "fbRads")
}
if (headers$status %in% c("502", "503", "504")) {
Sys.sleep(2)
if (retries < 3) {
flog.info(paste("Retrying query for the", retries +
1, " st/nd/rd time"), name = "fbRads")
mc$retries <- retries + 1
return(eval(mc, envir = parent.frame()))
}
}
if (inherits(tryCatch(fromJSONish(res), error = function(e) e),
"error") || is.null(fromJSONish(res))) {
stop("Some critical FB query error here.")
}
res <- fromJSONish(res)
if (res$error$code %in% 1:2) {
flog.error(paste("This is a temporary", shQuote(res$error$type),
"FB error:", res$error$message), name = "fbRads")
Sys.sleep(2)
if (retries < 3) {
flog.info(paste("Retrying query for the", retries +
1, " st/nd/rd time"), name = "fbRads")
mc$retries <- retries + 1
return(eval(mc, envir = parent.frame()))
}
}
stop(res$error$message)
}
res
}
Then you can run the function line-by-line and check all the internal variables, so you can just press Enter a couple times until it gets to assigning value to curlres
and check what the actual curl URL and params are
So I ran the code line by line. See (a) for the lines that contain "ERROR". See (b) for every line.
However, this merely returns the same information, that I had in the error message in the post on the top of this thread, doesn't it?
(a)
Browse[2]>
ERROR [2018-08-02 13:22:11] URL: https://graph.facebook.com/v3.1/act_XXXXXX/
debug: flog.error(paste("Method: ", method), name = "fbRads")
Browse[2]>
ERROR [2018-08-02 13:23:21] Method: GET
debug: flog.error(paste("Params: ", paste(capture.output(str(params)),
collapse = "\n")), name = "fbRads")
Browse[2]>
ERROR [2018-08-02 13:23:26] Params: List of 1
$ fields: chr "name,account_id,account_status,age,amount_spent,end_advertiser,funding_source,spend_cap,timezone_id,users"
debug: flog.error(paste("Header:", toJSON(headers)), name = "fbRads")
Browse[2]>
ERROR [2018-08-02 13:23:30] Header: {"x-app-usage":["{\"call_count\":0,\"total_cputime\":0,\"total_time\":0}"],"Strict-Transport-Security":["max-age=15552000; preload"],"x-fb-trace-id":["ZZZZZZZ"],"x-fb-rev":["ZZZZZZZZ"],"Content-Type":["application/json; charset=UTF-8"],"facebook-api-version":["v3.1"],"Cache-Control":["no-store"],"Pragma":["no-cache"],"Access-Control-Allow-Origin":["*"],"Expires":["Sat, 01 Jan 2000 00:00:00 GMT"],"WWW-Authenticate":["OAuth \"Facebook Platform\" \"invalid_request\" \"(#10) Permission Denied.\""],"X-FB-Debug":["ZZZZZZZZZZZZZZ=="],"Date":["Thu, 02 Aug 2018 11:22:03 GMT"],"Connection":["keep-alive"],"Content-Length":["109"],"status":["400"],"statusMessage":["Bad Request"]}
debug: flog.error(paste("Body:", res), name = "fbRads")
Browse[2]>
ERROR [2018-08-02 13:23:31] Body: {"error":{"message":"(#10) Permission Denied.","type":"OAuthException","code":10,"fbtrace_id":"ZZZZZZZZZZZ"}}
debug: if (headers$status %in% c("502", "503", "504")) {
Sys.sleep(2)
if (retries < 3) {
flog.info(paste("Retrying query for the", retries + 1,
" st/nd/rd time"), name = "fbRads")
mc$retries <- retries + 1
return(eval(mc, envir = parent.frame()))
}
}
(b)
> source("skript.R")
TRACE [2018-08-02 13:16:43] Initializing connection to account XXXXXX via API v3.1
debugging in: fbad_request(path = paste0("act_", accountid, "/"), method = "GET",
params = list(access_token = token, fields = scope), version = version)
debug: {
mc <- match.call()
method <- match.arg(method)
if (is.null(params$access_token)) {
if (missing(fbacc)) {
params$access_token <- getFromNamespace("fbacc",
"fbRads")$access_token
}
else {
params$access_token <- fbad_check_fbacc(fbacc)$access_token
}
}
if (missing(version)) {
if (missing(fbacc)) {
if (is.FB_Ad_Account(getFromNamespace("fbacc", "fbRads"))) {
version <- getFromNamespace("fbacc", "fbRads")$api_version
}
else {
version <- fb_api_most_recent_version()
}
}
else {
version <- fbad_check_fbacc(fbacc)$api_version
}
}
params <- fbad_check_curl_params(params)
b = basicTextGatherer(.mapUnicode = FALSE)
h = basicHeaderGatherer()
if (debug) {
print(params)
}
path <- sub(paste0("^https://graph.facebook.com/v", version,
"/"), "", path)
API_endpoint <- paste("https://graph.facebook.com", paste0("v",
version), path, sep = "/")
if (method == "DELETE") {
curlres <- tryCatch(res <- getURLContent(url = paste0(API_endpoint,
"?", paste(mapply(function(id, v) paste(URLencode(id),
URLencode(v), sep = "="), names(params), params),
collapse = "&")), .opts = curlOptions(headerfunction = h$update,
verbose = debug, writefunc = b$update, customrequest = "DELETE",
cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"),
connecttimeout = 3, timeout = 300)), error = function(e) e)
}
else {
curlres <- tryCatch(res <- do.call(what = paste0(ifelse(method ==
"GET", "get", "post"), "Form"), args = list(uri = API_endpoint,
.params = params, .opts = curlOptions(headerfunction = h$update,
verbose = debug, writefunc = b$update, cainfo = system.file("CurlSSL",
"cacert.pem", package = "RCurl"), crlf = ifelse(method ==
"GET", TRUE, FALSE), connecttimeout = 3, timeout = 300))),
error = function(e) e)
}
params$token <- params$access_token <- NULL
if (inherits(curlres, "error")) {
if (grepl("Network is unreachable", curlres$message) |
grepl("Empty reply from server", curlres$message) |
grepl("Failed to connect to graph.facebook.com",
curlres$message) | grepl("(Connection|Operation) timed out after",
curlres$message) | grepl("Unknown SSL protocol error",
curlres$message) | grepl("OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to graph.facebook.com",
curlres$message) | grepl("OpenSSL SSL_read: SSL_ERROR_SYSCALL",
curlres$message)) {
flog.error(paste("Possible network error:", curlres$message),
name = "fbRads")
flog.info(paste("Retrying query for the", retries +
1, " st/nd/rd time"), name = "fbRads")
Sys.sleep(2)
if (retries < 3) {
mc$retries <- retries + 1
return(eval(mc, envir = parent.frame()))
}
}
res <- curlres
}
if (inherits(res, "error")) {
if (log) {
flog.error(paste("URL: ", API_endpoint), name = "fbRads")
flog.error(paste("Method: ", method), name = "fbRads")
flog.error(paste("Params: ", paste(capture.output(str(params)),
collapse = "\n")), name = "fbRads")
}
stop(paste(ifelse(inherits(curlres, "error"), "This is a bug in the fbRads package. Please report on GitHub with a detailed output:",
"FB query failed:"), res$message))
}
res <- b$value()
headers <- as.list(h$value())
if (headers$status != "200") {
if (log) {
flog.error(paste("URL: ", API_endpoint), name = "fbRads")
flog.error(paste("Method: ", method), name = "fbRads")
flog.error(paste("Params: ", paste(capture.output(str(params)),
collapse = "\n")), name = "fbRads")
flog.error(paste("Header:", toJSON(headers)), name = "fbRads")
flog.error(paste("Body:", res), name = "fbRads")
}
if (headers$status %in% c("502", "503", "504")) {
Sys.sleep(2)
if (retries < 3) {
flog.info(paste("Retrying query for the", retries +
1, " st/nd/rd time"), name = "fbRads")
mc$retries <- retries + 1
return(eval(mc, envir = parent.frame()))
}
}
if (inherits(tryCatch(fromJSONish(res), error = function(e) e),
"error") || is.null(fromJSONish(res))) {
stop("Some critical FB query error here.")
}
res <- fromJSONish(res)
if (res$error$code %in% 1:2) {
flog.error(paste("This is a temporary", shQuote(res$error$type),
"FB error:", res$error$message), name = "fbRads")
Sys.sleep(2)
if (retries < 3) {
flog.info(paste("Retrying query for the", retries +
1, " st/nd/rd time"), name = "fbRads")
mc$retries <- retries + 1
return(eval(mc, envir = parent.frame()))
}
}
stop(res$error$message)
}
res
}
Browse[2]>
debug: mc <- match.call()
Browse[2]>
debug: method <- match.arg(method)
Browse[2]>
debug: if (is.null(params$access_token)) {
if (missing(fbacc)) {
params$access_token <- getFromNamespace("fbacc", "fbRads")$access_token
}
else {
params$access_token <- fbad_check_fbacc(fbacc)$access_token
}
}
Browse[2]>
debug: if (missing(version)) {
if (missing(fbacc)) {
if (is.FB_Ad_Account(getFromNamespace("fbacc", "fbRads"))) {
version <- getFromNamespace("fbacc", "fbRads")$api_version
}
else {
version <- fb_api_most_recent_version()
}
}
else {
version <- fbad_check_fbacc(fbacc)$api_version
}
}
Browse[2]>
debug: params <- fbad_check_curl_params(params)
Browse[2]>
debug: b = basicTextGatherer(.mapUnicode = FALSE)
Browse[2]>
debug: h = basicHeaderGatherer()
Browse[2]>
debug: if (debug) {
print(params)
}
Browse[2]>
debug: path <- sub(paste0("^https://graph.facebook.com/v", version,
"/"), "", path)
Browse[2]>
debug: API_endpoint <- paste("https://graph.facebook.com", paste0("v",
version), path, sep = "/")
Browse[2]>
debug: if (method == "DELETE") {
curlres <- tryCatch(res <- getURLContent(url = paste0(API_endpoint,
"?", paste(mapply(function(id, v) paste(URLencode(id),
URLencode(v), sep = "="), names(params), params),
collapse = "&")), .opts = curlOptions(headerfunction = h$update,
verbose = debug, writefunc = b$update, customrequest = "DELETE",
cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"),
connecttimeout = 3, timeout = 300)), error = function(e) e)
} else {
curlres <- tryCatch(res <- do.call(what = paste0(ifelse(method ==
"GET", "get", "post"), "Form"), args = list(uri = API_endpoint,
.params = params, .opts = curlOptions(headerfunction = h$update,
verbose = debug, writefunc = b$update, cainfo = system.file("CurlSSL",
"cacert.pem", package = "RCurl"), crlf = ifelse(method ==
"GET", TRUE, FALSE), connecttimeout = 3, timeout = 300))),
error = function(e) e)
}
Browse[2]>
debug: curlres <- tryCatch(res <- do.call(what = paste0(ifelse(method ==
"GET", "get", "post"), "Form"), args = list(uri = API_endpoint,
.params = params, .opts = curlOptions(headerfunction = h$update,
verbose = debug, writefunc = b$update, cainfo = system.file("CurlSSL",
"cacert.pem", package = "RCurl"), crlf = ifelse(method ==
"GET", TRUE, FALSE), connecttimeout = 3, timeout = 300))),
error = function(e) e)
Browse[2]>
debug: params$token <- params$access_token <- NULL
Browse[2]>
debug: if (inherits(curlres, "error")) {
if (grepl("Network is unreachable", curlres$message) | grepl("Empty reply from server",
curlres$message) | grepl("Failed to connect to graph.facebook.com",
curlres$message) | grepl("(Connection|Operation) timed out after",
curlres$message) | grepl("Unknown SSL protocol error",
curlres$message) | grepl("OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to graph.facebook.com",
curlres$message) | grepl("OpenSSL SSL_read: SSL_ERROR_SYSCALL",
curlres$message)) {
flog.error(paste("Possible network error:", curlres$message),
name = "fbRads")
flog.info(paste("Retrying query for the", retries + 1,
" st/nd/rd time"), name = "fbRads")
Sys.sleep(2)
if (retries < 3) {
mc$retries <- retries + 1
return(eval(mc, envir = parent.frame()))
}
}
res <- curlres
}
Browse[2]>
debug: if (inherits(res, "error")) {
if (log) {
flog.error(paste("URL: ", API_endpoint), name = "fbRads")
flog.error(paste("Method: ", method), name = "fbRads")
flog.error(paste("Params: ", paste(capture.output(str(params)),
collapse = "\n")), name = "fbRads")
}
stop(paste(ifelse(inherits(curlres, "error"), "This is a bug in the fbRads package. Please report on GitHub with a detailed output:",
"FB query failed:"), res$message))
}
Browse[2]>
debug: res <- b$value()
Browse[2]>
debug: headers <- as.list(h$value())
Browse[2]>
debug: if (headers$status != "200") {
if (log) {
flog.error(paste("URL: ", API_endpoint), name = "fbRads")
flog.error(paste("Method: ", method), name = "fbRads")
flog.error(paste("Params: ", paste(capture.output(str(params)),
collapse = "\n")), name = "fbRads")
flog.error(paste("Header:", toJSON(headers)), name = "fbRads")
flog.error(paste("Body:", res), name = "fbRads")
}
if (headers$status %in% c("502", "503", "504")) {
Sys.sleep(2)
if (retries < 3) {
flog.info(paste("Retrying query for the", retries +
1, " st/nd/rd time"), name = "fbRads")
mc$retries <- retries + 1
return(eval(mc, envir = parent.frame()))
}
}
if (inherits(tryCatch(fromJSONish(res), error = function(e) e),
"error") || is.null(fromJSONish(res))) {
stop("Some critical FB query error here.")
}
res <- fromJSONish(res)
if (res$error$code %in% 1:2) {
flog.error(paste("This is a temporary", shQuote(res$error$type),
"FB error:", res$error$message), name = "fbRads")
Sys.sleep(2)
if (retries < 3) {
flog.info(paste("Retrying query for the", retries +
1, " st/nd/rd time"), name = "fbRads")
mc$retries <- retries + 1
return(eval(mc, envir = parent.frame()))
}
}
stop(res$error$message)
}
Browse[2]>
debug: if (log) {
flog.error(paste("URL: ", API_endpoint), name = "fbRads")
flog.error(paste("Method: ", method), name = "fbRads")
flog.error(paste("Params: ", paste(capture.output(str(params)),
collapse = "\n")), name = "fbRads")
flog.error(paste("Header:", toJSON(headers)), name = "fbRads")
flog.error(paste("Body:", res), name = "fbRads")
}
Browse[2]>
debug: flog.error(paste("URL: ", API_endpoint), name = "fbRads")
Browse[2]>
ERROR [2018-08-02 13:22:11] URL: https://graph.facebook.com/v3.1/act_XXXXXX/
debug: flog.error(paste("Method: ", method), name = "fbRads")
Browse[2]>
ERROR [2018-08-02 13:23:21] Method: GET
debug: flog.error(paste("Params: ", paste(capture.output(str(params)),
collapse = "\n")), name = "fbRads")
Browse[2]>
ERROR [2018-08-02 13:23:26] Params: List of 1
$ fields: chr "name,account_id,account_status,age,amount_spent,end_advertiser,funding_source,spend_cap,timezone_id,users"
debug: flog.error(paste("Header:", toJSON(headers)), name = "fbRads")
Browse[2]>
ERROR [2018-08-02 13:23:30] Header: {"x-app-usage":["{\"call_count\":0,\"total_cputime\":0,\"total_time\":0}"],"Strict-Transport-Security":["max-age=15552000; preload"],"x-fb-trace-id":["ZZZZZZZ"],"x-fb-rev":["ZZZZZZZZ"],"Content-Type":["application/json; charset=UTF-8"],"facebook-api-version":["v3.1"],"Cache-Control":["no-store"],"Pragma":["no-cache"],"Access-Control-Allow-Origin":["*"],"Expires":["Sat, 01 Jan 2000 00:00:00 GMT"],"WWW-Authenticate":["OAuth \"Facebook Platform\" \"invalid_request\" \"(#10) Permission Denied.\""],"X-FB-Debug":["ZZZZZZZZZZZZZZ=="],"Date":["Thu, 02 Aug 2018 11:22:03 GMT"],"Connection":["keep-alive"],"Content-Length":["109"],"status":["400"],"statusMessage":["Bad Request"]}
debug: flog.error(paste("Body:", res), name = "fbRads")
Browse[2]>
ERROR [2018-08-02 13:23:31] Body: {"error":{"message":"(#10) Permission Denied.","type":"OAuthException","code":10,"fbtrace_id":"ZZZZZZZZZZZ"}}
debug: if (headers$status %in% c("502", "503", "504")) {
Sys.sleep(2)
if (retries < 3) {
flog.info(paste("Retrying query for the", retries + 1,
" st/nd/rd time"), name = "fbRads")
mc$retries <- retries + 1
return(eval(mc, envir = parent.frame()))
}
}
Browse[2]>
debug: if (inherits(tryCatch(fromJSONish(res), error = function(e) e),
"error") || is.null(fromJSONish(res))) {
stop("Some critical FB query error here.")
}
Browse[2]>
debug: res <- fromJSONish(res)
Browse[2]>
debug: if (res$error$code %in% 1:2) {
flog.error(paste("This is a temporary", shQuote(res$error$type),
"FB error:", res$error$message), name = "fbRads")
Sys.sleep(2)
if (retries < 3) {
flog.info(paste("Retrying query for the", retries + 1,
" st/nd/rd time"), name = "fbRads")
mc$retries <- retries + 1
return(eval(mc, envir = parent.frame()))
}
}
Browse[2]>
debug: stop(res$error$message)
Browse[2]>
Fehler in fbad_request(path = paste0("act_", accountid, "/"), method = "GET", :
(#10) Permission Denied.
debugonce
not only allows you to run the fn line by line, but it's still running in an interactive console, so you can run any R command in between those lines. So before the curlres
assignment line, check the value of the path and params so that you can compare that to your manual RCurl
call -- it should be pretty much the same.
Thanks for the clarification.
I ran the code up to this line just before the curles
assignment:
Browse[2]>
debug: API_endpoint <- paste("https://graph.facebook.com", paste0("v",
version), path, sep = "/")
Then I checked both path and params. Here is the resulting output:
Browse[2]> path
[1] "act_XXXXXXXX/"
Browse[2]> params
$access_token
[1] "YYYYYYY"
$fields
[1] "name,account_id,account_status,age,amount_spent,end_advertiser,funding_source,spend_cap,timezone_id,users"
Browse[2]>
I also doublechecked that XXXXXXXX
and YYYYYYY
are really the same numbers as in my RCurl
command and they really are.
Sorry to close this, but without any further info, I really cannot help with this. fbRads
uses RCurl
internally and hitting that exact same URL so not sure what might be the problem on your end.
I have a manually generated long term token ("YYYYYYYYYYYYY"). I generated this token as in developers.facebook.com/...#manually-getting-access-tokens.
The token works perfectly fine with this minimal R-Code:
However, the token does not work with this code:
Here I get this error message:
So it seems to me,
that fbad_init()
does not work with manually generated tokens. What can I do, to make it work with manually generated tokens? Or maybe there is a way to usefbRads
without thefbad_init()
-function?Thanks.