I can´t get the friendlist from facebook C# SDK (Windows phone) - facebook

i want to get the facebook friend's list from my application, but returns me data: []... empty! :(
the scenario it's this:
C#
const string QueryToGetFbInfo = "me";
const string QueryToGetFbPhoto = "me?fields=picture.width(200).height(200)";
const string QueryToGetFriendList = "me/friends?fields=name,picture.width(100).height(100)";
private void btnFacebook_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
FacebookSessionClient fbSession = new FacebookSessionClient("FB_APP_ID");
fbSession.LoginWithApp("public_profile, user_friends, read_friendlists, email", "custom_state_string");
}
private async void tbnShowfriends_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
FacebookSession session = SessionStorage.Load();
FacebookClient client = new FacebookClient(session.AccessToken);
// Get Facebook FriendList
dynamic friends = await client.GetTaskAsync(QueryToGetFriendList);
//Get Facebook user info
dynamic result = await client.GetTaskAsync(QueryToGetFbInfo);
GraphUser user = new GraphUser(result);
//Get profile picture from facebook
dynamic result1 = await client.GetTaskAsync(QueryToGetFbPhoto);
JsonObject json = result1.picture.data;
var picture = (IDictionary<string, object>)json;
....
}
Facebook App Config has the permissions... forgot some ?.. the new panel confuses me a little, Maybe I forgot something in the application settings...
when i select Api Graph, returns me, a friendlist, fine!
but when I select my application, I do not return anything
What I forgot ?... how can i fix this problem ?

You authed Graph Explorer using API v1.0 which means that that app will get all your friends until 4/30/2014. You app you authed using v2.0 or v2.1 which means that you will only get friends that are also using the app

Related

Get public photos from facebook using xamarin.Social

Can anyone help me to get public photos from a Facebook page. I'm developing a mobile app using Xamarin.Forms in which I need to get public photos from Facebook.
Currently I'm using Xamarin.Social to integrate Facebook in the app and I'm able to login into a Facebook account but not able to get public photos.
Use the Xamarin.Auth to query the relative facebook API link. For Example, to get the user name and ID you can use:
var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/v2.4/me"), null, _currentUser);
await request.GetResponseAsync().ContinueWith(t =>
{
if (t.IsFaulted)
return;
else
{
string mail = t.Result.GetResponseText();
Dictionary values =
JsonConvert.DeserializeObject>(mail);
bool s = values.TryGetValue("name", out _name);
bool i = values.TryGetValue("id", out _userId);
if(!s){
_name = "Error Getting Username";
}
if(!i){
_userId = "Error Getting Id";
}
}
});
To explore the Facebook API you can follow this link
Hope this helps.

How do I get actions posted via the graph to show up in hte users feed and not the activity log?

Currently when my app posts on a users behalf the custom action shows up in the activity log and not on the user's wall. I am expecting the action to show up in /me/feed in the open graph. I am using the c# library. Below is the code I am using:
public async Task JoinSmaxNation(int nationId)
{
dynamic parameters = new ExpandoObject();
parameters.smax_nation = String.Format(_smaxNationUrlFormat, nationId, UserId);
parameters.no_feed_story = false;
parameters.expires_in = 86400;
dynamic result = await _fb.PostTaskAsync("me/smaxsport:join", parameters);
}
It looks like the fb:explicitly_shared=true option was required.

Retriving Facebook posts from Profile via FB api

I have registered an app in facebook developers program and I can retrieve posts from facebook page using fb api, but I cannot retrieve posts from facebook profile. Should I use some different access token for both page or profile? Is there a different way for retrieving posts from facebook page and profile?
Any help will be appreciated!
You may need the user_status permission.
And you call the posts using this graph query {USER_ID}?fields=statuses
Prerequisite:- You need to have valida FB token for all the request:-
I am answering using c# language.
Step 1:- First you need to get the user's FB id using FB token
I am using Facebook SDK 7.0.6 for querying purpose
here's how to initialize the FB service which we will use in our consecutive calls.
FacebookService facebookService = new FacebookService(facebookToken);
var _facebookClient = new Facebook.FacebookClient(token);
Code snippet
public string GetFacebookID(string facebookToken)
{
dynamic result = _facebookClient.Get("me?fields=id");
if (result.ToString().Contains("id"))
{
return result["id"];
}
return string.Empty;
}
after that you can execute below method to get user's post using FB ID and token
public List<Post> GetPostsForUser(string facebookID)
{
List<Post> posts = new List<Post>();
dynamic result = _facebookClient.Get(facebookID + "/posts"); //Case Sensitive, Posts doesn´t work
if (result.ToString().Contains("data") && result.data.Count > 0)
{
foreach (var item in result.data)
{
posts.Add(new Post
{
ID = item.id,
Story = item.story,
Message = item.message,
Created_Time = Convert.ToDateTime(item.created_time),
Reactions = GetReactions(item.id)
});
}
result = _facebookClient.Get(GetNextURL(result.ToString()));
}
return posts;
}

Can I upload photos to a wall belonging to a fan (company) page wall using the Facebook Graph API?

I need to know if it's possible to make it so authorized users can upload photos to a fan page of a company (to the wall) using the graph API.
Also, is it possible to become like (become a fan) of a company page through the api once the user is authorized.
Yes you can. You need to obtain your admin access token by using the Graph API explorer (https://developers.facebook.com/tools/explorer) and with a call to
https://graph.facebook.com/{adminfacebookid}/accounts
this will list all pages and apps your admin has access to. Look for the fan page in question and copy the accessToken.
Next get the albumid by clicking on the id of the page, then adding /albums to the request
armed with this you can then post the image data to the url, using the facebook web client
like this
protected void PublishToPublicGallery(string accessToken, string filename, long albumId, string imagename)
{
var facebookClient = new FacebookClient(accessToken);
var mediaObject = new FacebookMediaObject
{
FileName = filename,
ContentType = "image/jpeg"
};
var fileBytes = System.IO.File.ReadAllBytes(filename);
mediaObject.SetValue(fileBytes);
IDictionary<string, object> upload = new Dictionary<string, object>();
upload.Add("name", imagename);
upload.Add("source", mediaObject);
var result = facebookClient.Post("/" + albumId + "/photos", upload) as JsonObject;
}

how to create a facebook event by using facebook api in asp.net

How to create a facebook event by using facebook api in asp.net.
Thanks.
public string CreateEvent(string accessToken)
{
FacebookClient facebookClient = new FacebookClient(accessToken);
Dictionary<string, object> createEventParameters = new Dictionary<string, object>();
createEventParameters.Add("name", "My birthday party )");
createEventParameters.Add("start_time", DateTime.Now.AddDays(2).ToUniversalTime().ToString());
createEventParameters.Add("end_time", DateTime.Now.AddDays(2).AddHours(4).ToUniversalTime().ToString());
createEventParameters.Add("owner", "Balaji Birajdar");
createEventParameters.Add("description", " ( a long description can be used here..)");
//Add the "venue" details
JsonObject venueParameters = new JsonObject();
venueParameters.Add("street", "dggdfgg");
venueParameters.Add("city", "gdfgf");
venueParameters.Add("state", "gfgdfgfg");
venueParameters.Add("zip", "gfdgdfg");
venueParameters.Add("country", "gfdgfg");
venueParameters.Add("latitude", "100.0");
venueParameters.Add("longitude", "100.0");
createEventParameters.Add("venue", venueParameters);
createEventParameters.Add("privacy", "OPEN");
createEventParameters.Add("location", "fhdhdfghgh");
//Add the event logo image
FacebookMediaObject logo = new FacebookMediaObject()
{
ContentType = "image/jpeg",
FileName = #"C:\logo.jpg"
};
logo.SetValue(File.ReadAllBytes(logo.FileName));
createEventParameters["#file.jpg"] = logo;
JsonObject resul = facebookClient.Post("/me/events", createEventParameters) as JsonObject;
return resul["id"].ToString();
}
I am using facebook graph apis with FacebookSdk from codeplex.
I am not able to post the venue with this code due to the open bug in facebook API. Other things work fine. I suggest you implement this venue parameters as well so that the functionality will work as soon as facebook resolves this issue.
Mark this as answer if it works for you.It will also help other people to save time on searching.
You might try this http://developers.facebook.com/docs/api