I have to develop an automated process for fetching my Facebook page insights. Since, Access token used for authentication purpose is temporary in nature. Therefore, I created a Facebook App and by providing all required permissions I generated a Page Access Token so that I could extend it's life-span. Reference Link : Java + RestFB API: Getting fresh Page Access Token without messing with AppID, appSecret
The following is my piece of code :
FacebookClient fb=new DefaultFacebookClient(accesstoken,Version.VERSION_2_7);
Connection<Insight> insights =fb.fetchConnection("119456244790112/insights", Insight.class,Parameter.with("since", "2016-08-01"),Parameter.with("until", "2016-08-27"));
for (Insight insight : insights.getData())
if(insight.getName().equals("page_impressions") && (insight.getPeriod().equals("day")) )
System.out.println(insight.getName()+"\t"+insight.getPeriod()+"\t"+insight.getValues());
'accesstoken' is the short-life Page access-token obtained by following the mentioned link.
The following is the Exception Stack I'm getting :
Exception in thread "main" com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: Invalid query (code 3001, subcode 1504028) at com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:1191) at com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:1117) at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:1058) at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:969) at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:931) at com.restfb.DefaultFacebookClient.fetchConnection(DefaultFacebookClient.java:356) at Main.main(Main.java:31)
Please help me finding the Page Insights using Page Access Token and hence extending it's life-span so that I could produce an automated process out of this. Thanks !