I found a web site that says this
Obtaining the Authorization Code
To use the Graph API, you must obtain an access token with the
read_insights permission. There is an important authentication
difference between application insights and insights from pages or
external websites:
You can use either a user access token (on behalf of the application
owner) or an application access token (on behalf of the application
itself) to get insights about an application.
You can only use a user access token (on behalf of the page owner) to
get insights about a page or an external website.
As far as I can tell the method you outlined using app_id and secret
is to get an application access token but that won't give you
permission to access the insights. In order to get the insights I need
a user access token and it seems like you are saying there is no way
to get that without physical user involvement.
Am I reading that right? Surely there has to be a way to get that data
without having a user actually interact with a browser.
Actually, sorry that I don't really know the detail. Since the documentation
says so, I guess using user access tokens with read_insights permission
would be able to read the insights.
But sorry I am too lazy to try it. Facebook has too many weird places
where document is wrong or not documented. For example, the term
"like" has so many meanings in different places, and they are not the
same, can't be read with this API or that API...
At least, the method I mentioned above worked for me, here's some
result I just tried:
>> response = rg.get("#{rg.app_id}/insights", {}, {:secret => true})
=> {"data"=>[{"name"=>"application_block_adds_unique",
"period"=>"day",
"id"=>"233082465238/insights/application_block_adds_unique/day",
"values"=>[{"end_time"=>"2011-04-15T07:00:00+0000", "value"=>6},
{"end_time"=>"2011-04-16T07:00:00+0000", "value"=>0},
{"end_time"=>"2011-04-17T07:00:00+0000", "value"=>7}],
"description"=>"Daily Blocks of your app (Unique Users)"}, ...
[snipped]
>> response['data'].size
=> 181
I don't know if this is the full result though. According to the permission
on the access token, Facebook would give you different results.
Maybe using read_insights permission from some user would give
you more data, or the data specific to that user, I don't know.
If this is true, to workaround a user interaction, you could try to grant
the user access token with read_insights along with offline_access
permission, and put that persistent access_token directly inside your
program. This way, as long as the user didn't change the permission,
it should work until Facebook changed something again.
Hope this is helpful, and you can get fetching your data soon.
I was able to get insights for the app I defined using the app_id but
not the page using the page object it but I'll try it again using your
method and see what happens.
>
> If this is true, to workaround a user interaction, you could try to grant
> the user access token with read_insights along with offline_access
> permission, and put that persistent access_token directly inside your
> program. This way, as long as the user didn't change the permission,
> it should work until Facebook changed something again.
>
If the access token does not expire I could to this I think.
> Hope this is helpful, and you can get fetching your data soon.
>
Thanks. I will try your method above.