Skip to content
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

Error in content$data[[1]] : subscript out of bounds in getInsights #25

Closed
theclue opened this issue Feb 23, 2015 · 7 comments
Closed

Comments

@theclue
Copy link

theclue commented Feb 23, 2015

Hello Pablo,

first of all, tnx for your work..this package is really a lifeboat, to me!

Said that, I must say that I'm not able to make getInsights working. Whatever parameters I put, I always get this error: Error in content$data[[1]] : subscript out of bounds

Some examples ->

From a page I own:
circle <- getInsights(object_id="9thcirclegames", token = fb.connection, metric = "page_impressions")

circle <- getInsights("me", token = fb.connection, metric = "page_impressions")

A post by me (not the page):
example_post <- circle <- getInsights(object_id="10152670074275267_10152659686895267", token = fb.connection, metric = "post_impressions", period='days_28')

perhaps I'm using the function in the wrong way?

@chipoglesby
Copy link

Just to echo @theclue thank you for all of your work!

Currently, I'm having the same issues when trying to query getInsights.

Example:
insights <- getInsights(object_id='xx_pageid_xx',
token=fb_oauth, metric='post_impressions', period='days_28')
R returns:
Error in content$data[[1]] : subscript out of bounds

The package does work for getUsers and getPage, which is how I found my page's id. I'm not sure if you have any ideas what could be causing this?

Thanks,

Chip

@lbollar
Copy link

lbollar commented Mar 5, 2015

Like @theclue, I get the same subscript out of bounds error for getInsights(). I am trying to query this information for a page I was given access to, and by using the Graph API Explorer from developers.facebook.com, I was able to confirm that I do have authority to query this information.

I actually get two different errors based on whether I try post_impressions or page_impressions, and this might just be due to stupid user error, but like @theclue I have tried different parameters and cannot get the function to work.

insights <- getInsights(object_id="XXXXXXXXXXX", token=fb_oauth, metric='page_impressions')
Error in insightsDataToDF(content$data, content$data[[1]]$values) :
argument "metric" is missing, with no default

insights <- getInsights(object_id="XXXXXXXXXXX", token=fb_oauth, metric='post_impressions')
Error in content$data[[1]] : subscript out of bounds

@weatherlisa
Copy link

Rfacebook is a great package! I'm loving playing around with it.

I am having the same problem as @lbollar with getInsights()
I get the error:
insights <- getInsights(object_id="XXXXXXXXXXX", token=fb_oauth, metric='post_impressions')
Error in content$data[[1]] : subscript out of bounds

Has anyone had any luck yet?

@shenjunfei
Copy link

I also have the same problem like you guys.
Every time I call getInsights():
insights <- getInsights(object_id = "xxxxxxxxxx", token = fb_oauth, metric = "page_impressions")
an error is returned:
Error in content$data[[1]] : subscript out of bounds

I also tried to debug this by
debug(getInsights)
and execute the function line by line
function(object_id, token, metric, period = "day", n = 5)
The first line
url <- paste0("https://graph.facebook.com/", object_id, "/insights/", metric, "?period=", period)
and second line
content <- callAPI(url = url, token = token)
are OK, but the error occurred when I browse to the third line
l <- length(content$data[[1]]$values)
Error in content$data[[1]] : subscript out of bounds

If I skip this and the following several lines about l
if (l == 0) {
stop("No public posts mentioning the string were found")
}
I finally get an output a few lines away here
if (length(content$data) == 0) {
stop("No public posts mentioning the string were found")
}

Maybe "No public posts mentioning the string were found" is exactly what I should get for this input?

And the error says
Error in content$data[[1]] : subscript out of bounds
It seems to say that the first element of the first list content$data does not exist, because the list content$data is empty?
Actually after executing the following line
content <- callAPI(url = url, token = token)
I find content is a list of 2, the first is data, and content$data is an empty list. Therefore content$data[[1]]$values does not exist and this line breaks down:
l <- length(content$data[[1]]$values)
I'm wondering what is supposed to be in the list content$data when everything goes right, and what is wrong here.

@mpiccirilli
Copy link
Collaborator

You will only be able to use getInsights() if you're an owner or admin of the page you're calling.

@shenjunfei yes, the error is thrown because content$data is empty. There isn't anything wrong with receiving the "subscript out of bounds" error, but an additional condition could be added to handle the case when content$data is empty. Below is what it would look like if you used this function on a page you own/admin.

$data
$data[[1]]
$data[[1]]$id
[1] "230719923749613/insights/page_views/day"

$data[[1]]$name
[1] "page_views"

$data[[1]]$period
[1] "day"

$data[[1]]$values
$data[[1]]$values[[1]]
$data[[1]]$values[[1]]$value
[1] 2

$data[[1]]$values[[1]]$end_time
[1] "2015-03-22T07:00:00+0000"

$data[[1]]$values[[2]]
$data[[1]]$values[[2]]$value
[1] 4

$data[[1]]$values[[2]]$end_time
[1] "2015-03-23T07:00:00+0000"

$data[[1]]$values[[3]]
$data[[1]]$values[[3]]$value
[1] 25

$data[[1]]$values[[3]]$end_time
[1] "2015-03-24T07:00:00+0000"

$data[[1]]$title
[1] "Daily Page Views"

$data[[1]]$description
[1] "Daily: Page views (Total Count)"

@SDBanswers
Copy link

I'm an administrator for the page that I'm concerned with, but getInsights() doesn't work for me, either. I can't figure out what the problem is.

@pablobarbera
Copy link
Owner

I fixed getInsights and everything should work now. (Sorry it took so long -- I didn't have access to a FB page with insights activated, so I had to create it first to see where the error was.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants