Facebook API get subsribers of a page? - c#

I've been searching the Graph API Explorer and documentation for a long time, but I really can't find anything.
I need a simple GET request like the me/subscribes just with page-id/subscribers or something like that. Does anyone know the get I must send to get a Count of subscribers of a page?
BTW I'm using Facebook SDK and I'm using this as GET:
var fb = new FacebookClient(useraccesstoken);
dynamic result = fb.Get("i want to get subscribers of a page id what to do??");

The /me/subscribers end-point was available to users' only, and has since been removed with Graph API 2.0, along with the user_subscriptions permission.
You can get a count of the subscribers / likes for a page as follows:
/{page-id}?fields=likes
This will return an a count for the total number of likes for a given {page-id}:
{
"likes": 123456,
"id": "{page-id}"
}
Trying to access the subscribers of a page is the same as trying to access all the users that have liked the page, which Facebook doesn't allow.

Related

Google My Business API to fetch Reviews

I want to know how can I use GMB API to fetch reviews. According to google documentation we have to make a GET request to https://mybusiness.googleapis.com/v3/{name=accounts/*/locations/*}/reviews
But what is meant by {name=accounts/*/locations/*} and from where we can get the value of accounts & locations.
Also this requires OAuth 2.0. If I get a access_token then GET request will be like this:-
https://mybusiness.googleapis.com/v3/{name=accounts/*/locations/*}/reviews?access_token=token
This is very confusing. Can somebody tell me how to use GMB API correctly to fetch google reviews.
Using Google OAuth 2 Playground
For testing acquisition of Google reviews
Create a project
Console.cloud.google.com
Sign in as {projectowner}#google.com
Select a project from the dropdown in the header or click new project
Go to APIs & Services in the left menu
Enable the Google My Business API; this requires validation by Google and may take a couple of days. They will email you.
Go to developers.google.com/oauthplayground
Using the settings gear, set OAuth flow to Client-side and click Use your own OAuth credentials
Get the client id from console.developers.google.com/apis and paste it in
Put this into scope: https://www.googleapis.com/auth/plus.business.manage and authorize it with {projectowner}#gmail.com
Exchange auth code for token
To get the account name:
Set Request URI to https://mybusiness.googleapis.com/v4/accounts and send a Get request
Copy the entire string value at “name”: not including quotes; it may be 20+ numeric digits
To get location names:
Set Request URI to https://mybusiness.googleapis.com/v4/accounts/{paste account name here}/locations where {paste ... here} is the account name you copied
The returned JSON contains all of your locations
Copy the location names including quotes and commas to a temporary holding document; they will be used in a JSON array in the next step
To get multiple locations’ reviews
a. Set Request URI to https://mybusiness.googleapis.com/v4/accounts/{account name here}/locations:batchGetReviews and the Method to Post
b. Set Request Body to
{
"locationNames": [
"accounts/999999999999999999999/locations/88888888888888888888",
"accounts/999999999999999999999/locations/77777777777777777777",
.
.
.
"accounts/999999999999999999999/locations/11111111111111111111"
],
"pageSize": 200,
"orderBy": "updateTime desc",
"ignoreRatingOnlyReviews": false
}
using the account names you saved from the location JSON for each line of the array
If you have more than 200 total reviews you will have to add "pageToken": string into the JSON body where string is a value returned in the preceding POST.
But what is meant by {name=accounts//locations/} and from where we can get the value of accounts & locations.
To get this details first get the account using the following API (https://mybusiness.googleapis.com/v4/accounts?access_token=#####)
Once you have the account list, fetch Account Location list using the following API (https://mybusiness.googleapis.com/v3/" + name + "/locations) in the response of this API you will get the {name=accounts/*/locations/*}.
Also this requires OAuth 2.0. If I get a access_token then GET request will be like this: https://mybusiness.googleapis.com/v3/{name=accounts/*/locations/*}/reviews?access_token=token
Yes, that is correct.
Let me know if this work's for you.

Facebook page /feed missing images

I was using the Facebook Public API Feed for the longest time and since they deprecated it I've been trying to find a replacement method in C#.
I am able to get my page posts but any post that contains images I only get the message and no images. After spending the past weekend trying to find a way I am desperate to know if anyone has had any success in getting full page post content from the Facebook C# SDK library.
Here is what I have and it works for getting the posts but they do not contain any images.
var fb = new FacebookClient
{
AppId = ConfigurationManager.AppSettings.Get("FacebookAppID"),
AppSecret = ConfigurationManager.AppSettings.Get("FacebookAppSecret"),
AccessToken = ConfigurationManager.AppSettings.Get("FacebookAccessToken")
};
var pageFeed = string.Format("/v2.4/{0}/feed", _facebookPageId);
dynamic response = fb.Get(pageFeed);
Since the upgrade in Graph API v2.4. Only a limited set of data is sent via FB unless specifically requested. You should pass the fields parameter with the keyword of data which you would like to retrieve.
A list of keyword is available here
In your case, the request statement would be:
var pageFeed = string.Format("/v2.4/{0}/feed?fields=id,message,picture", _facebookPageId);
To get all pictures from a post: replace picture with attachments, as picture will return the very first picture linked to the post.
var pageFeed = string.Format("/v2.4/{0}/feed?fields=id,message,attachments", _facebookPageId);

Using Facebook API to access public group event data

I'm developing a public website and what I want to do is pretty straightforward, but I'm pulling my hair out trying to get everything working right.
I administer an open Facebook group and I want to display the public facebook events of this group on my website.
I can't seem to figure out how to setup my authentication so that I can access the event data. Here is my code for using my application to get an auth token:
var fb = new FacebookClientWrapper();
dynamic result = fb.Get("oauth/access_token", new
{
client_id = AppSettings.AppID,
client_secret = AppSettings.AppSecret,
grant_type = "client_credentials"
});
fb.AccessToken = result.access_token;
I know this works fine because I can access some information - for example, if I access a specific event by its ID, I can retrieve that information.
The problem occurs when I try to retrieve a list of events with fields within a date range:
[HttpGet]
public object GetEventDetails(string unixStartDateTime, string unixEndDateTime)
{
var parms = new Dictionary<string, object>();
parms.Add("fields", new[] { "id","name","description","start_time","venue" });
if (!String.IsNullOrEmpty(unixStartDateTime)) { parms.Add("since", unixStartDateTime); }
if (!String.IsNullOrEmpty(unixEndDateTime)) { parms.Add("until", unixEndDateTime); }
var eventsLink = String.Format(#"/{0}/events", AppSettings.GroupID);
return ObjectFactory.GetInstance<IFacebookClient>().Get(eventsLink,parms);
}
(I'm aware that even if this did succeed, the return value wouldn't be serializable - I'm not concerned about that quite yet).
This GET request returns the following message:
(OAuthException - #102) A user access token is required to request this resource.
So the message is quite clear: I need a user access token to get the data I've requested. The question is - what is the best way to do this? Can I give my application a certain permission to read this data? I've looked over all the permissions available to apps, but I don't see one that would do the trick.
I don't want to require people to log onto Facebook to look at public event data, and I love the idea of allowing people with no technical experience to essentially update the website content by posting Facebook events to the group. Right now, I have to duplicate anything they do.
I would think this kind of application would be very common, but no matter what I've read or tried, I can't quite find an example of the same thing that works.
From the docs at https://developers.facebook.com/docs/graph-api/reference/v2.0/group/events you need
A user access token for a member of the group with user_groups permission.
To avoid the hassle, you could create such an Access Token via the Graph Explorer and then store it in your application. Remember to exchange that Access Token to a long-lived one (https://developers.facebook.com/docs/facebook-login/access-tokens/#extending), and that you have to renew the Access Token every 60 days afterwards.

Get list of invited friends from MultiFriendSelector

I am using ASP.net C# for a web application that integrates with the Facebook API. My application will allow users to create a group for sharing code. I need to use Facebook API to let the user invite friends from Facebook to join his group on my application. This is a requirement for an assignment so please don't give suggestions to create a group of users that are registered with my site only.
Until now I have the request dialog with all the friends listed (MultiFriendSelector()) with this code:
<p> Click <span id="span-link" onclick="sendRequestViaMultiFriendSelector(); return false;">here</span> to add friends from your Facebook account to your group! </p>
But I am stuck on how to get the id's and details of these invited users so I can save them in my database and allow them to access the group they were invited to. How can I do this please? I can't seem to find anything related to this.
By the way I know that there is a related question which gives this code:
if( Request["ids"] != null )
((Site)Master).FbInviteSent(Request.QueryString.GetValues("ids"));
but I don't know what Master is and I cant get it to work.
Thanks for your help :)
Whenever you call the request dialog, you may pass a callback function:
function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: 'My Great Request'
}, requestCallback);
}
The requestCallback will receive the response, and this response returns the facebook id of the users, who were invited
function requestCallback(response){
for (var i = 0; i < response.to.length; i++) {
fb_id = response.to[i];
// Do something with fb_id.
}
}
From looking at the code in the other answer it looks like the facebook API will call back to your page with a query string parameter of ids.
I.e. It will call you site with a url like this.
http://wwww.yoursitesulr.com/mypage.aspx?ids=13,22,44
You can then pull out the id's from the query string using
string myIds = Request.QueryString["ids"];
You can then convert them to a array.
var ids = myIds.Split(',');
If you are using MVC then you can take advantage of the model binders and just put an int array in your view model and it will get bound automatically.
The answer below addresses your specific issie so I would use this as a starting point.
Faceboook: Posting to Multiple Friend's Walls Using Multiple Friend Selector and JS SDK
Let me know if you have any questions regarding the above solution.
Regards
Steve

Photos uploaded via C# SDK has no "Like" button

I am building an application where users will upload photos which will be stored in an album on their Facebook account. Currently, I am using the C# SDK to achieve this, and I managed to get the photo uploaded.
When I tried to query the photo using the following FQL in the Graph API explorer:
select object_id, like_info from photo where object_id=[my_object_id]
I get the following result:
{
"data": [
{
"object_id": "11111111111111111",
"like_info": {
"can_like": false,
"like_count": 0,
"user_likes": false
}
}
]
}
Uploading a photo by posting directly to the Graph API endpoint https://graph.facebook.com/me/photos?access_token=[my_access_token] and doing a FQL on the resulting ID gives the same result - the can_like has a value of false. On both occasions, the "Who can see posts this app makes for you on your Facebook timeline?" setting for the app was set to "Public".
If I view the photo page, I can see the photo but there are no "Like" or "Comment" buttons. Upon further investigation, I found that the "Like" and "Commment" buttons will only appear if I (or rather my access token's user) is a friend of the uploader. Is it possible to make the uploaded photo "Likeable"? My objective is to allow users who come to my app to be able to "Like" the individual photos without having to be a friend of the person who uploaded it. Can this be achieved or am I missing something? Thanks.
This is restriction of facebook, but i have found a workaround, when user have their subscriptions enabled here: https://www.facebook.com/about/subscribe anyone can like/comment their photos...

Categories

Resources