Accessing Facebook events in groups through Graph API - facebook-graph-api

I'm new to Facebook's API. I'm trying to use Facebook's Graph API to access the event data of a group (not a page).
I'm using a Facebook app to make the API calls via a simple Perl script. I can see the events exist in the groups when I visit the group on Facebook with my browser. But the events are not getting returned by the API call. I just get {"data":[]} returned. My Perl script works fine with API calls for public pages.
Is it possible to get access to the group event data via the API? If so, how? If not, is there some other way I can get access like making the API calls using my user account on Facebook?
use strict;
use warnings;
use JSON::Parse 'parse_json';
use LWP::UserAgent;
use Data::Dumper;
my $ua = LWP::UserAgent->new;
my $response = $ua->get('https://graph.facebook.com/oauth/access_token?client_id=blah&client_secret=blah&grant_type=client_credentials');
my $access_token = $response->decoded_content;
my $json = $ua->get('https://graph.facebook.com/v2.6/WestfieldCulturalDistrict/events?' . $access_token);
print Dumper $json->decoded_content;

https://developers.facebook.com/docs/graph-api/reference/v2.6/group/events
A user access token for a member of the group with user_groups permission.
...
By default this will only return events within the last two weeks, use until or since parameters to modify this range.
There is no user_groups permission anymore, i guess that´s why there is an important message on that page:
This document refers to a feature that was removed after Graph API v2.5.
So either that´s a bug in the Facebook docs, or it´s just not possible anymore to get group events. Not even with a User Token. You should try with one though (and user_managed_groups).

Related

How do I set UserID in AWS XRay sdk traces within dotnet core web api using httpcontext

I'm interested in setting an xray "trace" UserID within an asp.net core web api (based on authenticated user claims contained within HttpContext User.Claims)
To me, it makes sense that if OAuth token has for example some claims containing identity information regarding the client of an api, that the xray trace have some attribute which is also contained within the claims (user email, or even custom claim)
What method do I need to call on the AWS XRay SDK in order to manually set this value?
Is there a method on an instance of AWSXRayRecorder?
Ive tried the below but this does not appear to be the solution, rather just a weak attempt or educated guess.
AWSXRayRecorder recorder = AWSXRayRecorder.Instance;
recorder.AddAnnotation("UserID", "123");
recorder.AddAnnotation("User", "456");
How does the sdk allow this type of control? Does it allow this type of control such that we can set the value of UserID?
Here you can see within the analytics tab, User is not set (showing "-")
I understand I can use annotations in a similar way, but here what I am specifically asking about is what shows on the UI above, the "User"
Ive also tried the below, however, this does not appear to have any effect on what I see on the analytics
var segment1 = (Segment)AWSXRayRecorder.Instance.GetEntity();
var segment2 = (Segment)AWSXRayRecorder.Instance.TraceContext.GetEntity();
segment1.SetUser("User1");
segment2.SetUser("User2");
I think currently you can set values like userID or user in the trace data using AddAnnotation or AddMetadata method. Would you be able to explain why AddAnnotation method is not the right usage for your use case? I don't think X-Ray SDK supports any other APIs to set such values other than AddAnnotation and AddMetadata methods.

how to ban a facebook user from a facebook application, through api

We are having a facebook App we have detected some abusive users so we want to stop them from logging into our app, Any thoughts? There are examples given but Fb docs say those api's are deprecated now
You could just detect them on your own and set a flag in your database. They will still be able to use Facebook Login, but they will not be able to do anything in your App if they are flagged.
Either way, i did some Google research and found out that it may be possible with a simple POST (or DELETE) request to the /app-id/banned endpoint:
BAN
https://graph.facebook.com/{app-id}/banned
POST parameters:
access_token (A simple App Access Token)
uid (comma separated list of user IDs)
UNBAN
https://graph.facebook.com/{app-id}/banned/{user-id}
DELETE request, only access_token as parameter
It is not really documented though, but easy to test.

How to get user's username in v2.0 or later of Facebook's Graph API

I used to get the user's username in the API 1.0 fairly easily, using /me and getting the username property of the response object.
Now I'm getting this error with API 2.0:
"(#12) username is deprecated for versions v2.0 and higher"
The only way I found to get this until now was to use FQL, but now it seems deprecated.
Is there a way around this?
I don't mean to be unhelpful, but it appears access to username has been removed from the API, as far as I can tell. Places where an app may have been using username, such as in the old share dialogs, can no longer do that when used with the 2.0 API. I think its also a way of preventing apps from having access to usable unique identifiers outside of the app scope - any user IDs you retrieve under 2.0 API are specific to your app alone.
I found a simple workaround that involves a get request to Facebook. Instead of the username, Facebook will give you an ID that is unique to your application.
I have found that making a request to https://www.facebook.com/[profile_id] will then redirect to the user's real profile. The username can be extracted from the redirect URL.
Example:
> curl -i https://www.facebook.com/710290539
HTTP/1.1 301 Moved Permanently
Location: https://www.facebook.com/colinskow
(Note: Since I am the owner of the app in test mode, this could possibly be an exception. Please let me know in comments if you are able to confirm this in a production environment.)
As a workaround you can use the email as a unique identifier. Email address can be retrieved using "email" as the permission scope.
Facebook has removed the username field from the new API version. It is not possible to retrieve the username. But Facebook provides an application specific unique ID. If you need to share the same user between several apps you can use the newly introduced Business Mapping API. This allows to add all the required apps to a group. In this case the ID will be unique among all the apps in the group.
More information on Business Mapping API is available at https://developers.facebook.com/docs/apps/for-business 1

Facebook ads api workflow

My app got white-listed for using the Ads API.
I was wondering in regarding to the authentication flow.
Say, that I need to retrieve and execute actions via the API on daily tasks ( with no user interaction) , I find the authentication process quite cumbersome.
Is there a way to work with my app access token instead of a user access token?
I want to be able to approve my app only once for each user and then to be able to work with no user interaction.
Can I achieve this?
App access token is not relevant for this case.
I had to work with the user access token.
I followed this doc: https://developers.facebook.com/docs/reference/ads-api/
Eventually , one should use some client side code in order to get a user permissions and then make another request for getting the user token.
So you'll have to call
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=ads_management,offline_access&response_type=code
Get the authentication code and make another call:
https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&client_secret=YOUR_APP_SECRET&code=AUTHORIZATION_CODE
Then you'll get an access token which is valid only for two months, in opposed to what Facebook docs says in here:
https://developers.facebook.com/roadmap/offline-access-removal/
"Ads APIs are special cased to allow collection of statistics offline. PMD partners should use server-side OAuth flow in order to receive a non-expiring token rather than a token that has longer expiration time."
Too bad that the access token is not really valid forever...
According to "Exception 4" in this document , if you have Ads API access you should be able to get a non-expiring token if you use the correct workflow. Following the guidelines outlined here, if you use the server side OAuth flow, to make the following request you should get a non-expiring token:
GET /oauth/access_token?
grant_type=fb_exchange_token&
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={short-lived-token}
thx for the feedback regarding the Access token process being cumbersome. Because this is a one to many solution - a single App ID can manage multiple ad accounts, on behalf of multiple people - we need to make calls on behalf of people.
You should be able to get a persistent access token for Ads API. If you are not getting it, please provide exact steps you are following so we can see if there is a bug or you might be missing a step.
Thx.

Fetching one's old Facebook status messages

I want to fetch one's old Facebook status. I have written the code for the same but it looks like it is not working for me. The steps that I have followed are as follows:
First I use the below API to seek the code from Facebook (by prompting user to log in to the Facebook page)
https://www.facebook.com/dialog/oauth?client_id=xxyy&redirect_uri=http://xxyy/home.aspx&scope=publish_stream,read_stream";
Then I seek the AccessToken by passing the code obtained in the above point to the below api as:
https://graph.facebook.com/oauth/access_token?client_id=xxy&redirect_uri=http://xxyy/home.aspx&client_secret=xxyy&code=zzz"
Now there is a problem. I am not able to understand which API I need to use to fetch the old status of the logged in user. I guess I have the access token which is the key to fetching the info. But I am not able to find the relevant API.
I would recommend that you use FQL.
//PHP example:
$fql_query_url = 'https://graph.facebook.com/'
. '/fql?q=fql?q=SELECT status_id, message FROM status WHERE uid=me()'
. '&' . $access_token;
$fql_query_result = file_get_contents($fql_query_url);
The graph API and "post" feed is what you need. I don't usually do this but I need my old statuses!
Following code works for me for fetching Facebook Conversation:
String s = facebook.request("me/inbox");
System.out.println("Message...."+s);