Have gotten the foundation in place, but now, finding myself wanting to play around with my
application's user's profile pictures; I'm stumped....and have been for quite some hours...
Firstly, my oauth_token / access_token is obtained, using the official (though Alpha ;-)
Facebook C# SDK and only utilize the Graph API.
FBapi.Get("/" + friend.Dictionary["id"].String + "/picture");
leads to an exception due to not returning a JSONObject, and
using the complete http://graph.facebook.com/me/picture is forwarded/translated to the image's URL.
Trying a more direct approach didn't pan out either :
WebClient wcImg = new WebClient();
wcImg.DownloadFile("/" + friend.Dictionary["id"].String + "/picture", "name_blame.jpg");
Some details are lacking in my question; I beg your pardon, am very tired and will edit later if uproar commences.
Ideas?
Addendum :
Boy, afflicted by code blindness I was indeed! However, your sensibility gave me what I needed (Zynga, tremble in my canvas ;-).
For sake of curiosity...it appears there's no JSON template(pardon my lack of lingo) available for profile pictures? Then how do one go about obtaining a fleshed out, Graph API Photo of that profile picture (if available)?
The picture in Graph API is a bit special animal. It doesn't return json, it directly forwards to the image. It was made so that you can use this url right in html:
<img src="http://graph.facebook.com/<UID>/picture"> - displays avatar
Now if you need to know actual picture URL it redirects to there are 2 options:
Read redirect headers from that graph URL.
Use FQL:
select pic_square from user where uid=12345
There is alot of other info that can be extracted about a user using FQL (including pictures in other sizes).
Also, if You want to show big profile photo, use this:
http://graph.facebook.com/<UID>/picture?type=large
You can get ALL friends' profile pictures (direct Links to the photos), in a single GET request:
https://graph.facebook.com/me/friends?access_token=[oauth_token]&fields=name,id,picture
Then use Json to Decode the string.. and that's all...
NJoy ^_^
Related
My question is how to save all the triples in my graph variable from URI. When I execute my code:
IGraph g = new Graph();
g.LoadFromUri(new Uri("http://data.linkedmdb.org/page/film/14931"));
I get only 2 triples in that graph, my question is how can I get others like actors, director, editor,...?
Those 2 triples are:
{http://data.linkedmdb.org/page/film/14931 , http://www.w3.org/1999/xhtml/vocab#stylesheet , http://data.linkedmdb.org/snorql/style.css}
{http://data.linkedmdb.org/page/film/14931 , http://www.w3.org/1999/xhtml/vocab#alternate , http://data.linkedmdb.org/data/film/14931}
The LinkedMDB homepage includes:
Start Exploring
Use your web browser to explore the HTML view provided by the D2R
server at
http://data.linkedmdb.org/page/film/2014
Use the following
semantic web browsers to explore the resource URI
http://data.linkedmdb.org/resource/film/2014
It sounds like you should request http://data.linkedmdb.org/resource/film/14931 instead. (Note that retrieving that in a web browser, you'll get redirected to the first. Be sure to try it in your code, not just in a web browser.)
I'm using Facebook .Net SDK(http://facebooksdk.net/) in my application. I need post an image to the wall of the user or his page.
I have this piece of code to try do this:
var postUrl = "<fbid>/feed";
var fbParameters = new Dictionary<string,object>();
fbParameters["message"] = postRequest.FacebookPostContent;
if (postRequest.MediaData != null && postRequest.MediaData.Length > 0)
{
var stream = new MemoryStream(postRequest.MediaData);
if (postRequest.ContentType.Equals("image/jpeg"))
{
postUrl = postUrl.Replace("/feed", "/photos");
fbParameters["picture"] = new FacebookMediaStream { ContentType = postRequest.ContentType, FileName = DateTime.UtcNow.ToString("ddmmyyyyhhmmss") + "-photo.jpeg" }.SetValue(stream);
}
}
if (!string.IsNullOrWhiteSpace(postRequest.FacebookPageId))
{
fbUserID = postRequest.FacebookPageId;
}
postUrl = postUrl.Replace("<fbid>", fbUserID);
var result = await facebookClient.PostTaskAsync(postUrl, fbParameters);
Look at my postUrl variable. I update the with the user ID in Facebook or the PageID if it is a page so the post should be properly posted in the right object. If there is some image to upload, so add it to the dictionary.
So, with it in mind, I have the following questions:
When the fbUserID is a user ID, the post happens perfectly, with the image and description but, when the ID is a PageID, only the description text is posted and image is just ignored(the user has the manage_page permissions so I dont think it is a permission issue). What I'm doing wrong that the image is not being posted to the page's wall?
If I want to post a video instead of a image, what should I change in this code?
Already saw many problems with other technologies here in SO but never a conclusive solution.
Thank you very much for the help, I really appreciate.
Regards,
Gutemberg
Got it!
Facebook creates a different section inside the page called Recent Posts by Others on Test Page where people allowed to post images will be there, like an attachment icon. In order to post directly to the page's feed/wall, all I need to do is instead of use the user access_token(even if user granted manage_pages permission) just use the access_token that comes in /me/accounts object for the respective page.
About the video post, I just set the ContentType to "video/mpeg" and at server instead of set picture parameter on dictionary, I've set the video field with the video byte[].
Thanks!
Regards,
As an alternative you could try the Share Content button shown in one of the answers here:
Upload video on Facebook using Graph REST API on Windows Phone 8.1
I found that to be easier than tackling authorization and manually posting.
When I use the Live Client Auth sdk, I can get a url to a thumbnail for the currently logged in user. How can I get the equivalent thumbnail for a contact of the user?
I know that the contact returned by new ContactPicker().PickSingleContactAsync() has a GetThumbnailAsync method, but that returns a bitmap and I'd rather just use the url. Is that possible? Is there a way to get the profile pic for any arbitrary email?
I know that the contact returned by new
ContactPicker().PickSingleContactAsync() has a GetThumbnailAsync
method, but that returns a bitmap and I'd rather just use the url. Is
that possible?
No. See documentation http://msdn.microsoft.com/en-us/library/windows/apps/br224875.aspx
Is there a way to get the profile pic for any arbitrary email?
Someone else seems to have resolved this. Check the answer at https://stackoverflow.com/a/12082001/2012977
The problem is that 1) Facebook seems so fluid with how it allows developers to interact with it (FBML, iFrame, different versions of SDKs) and 2) Everything I find is either PHP or Javascript and I have NO experience with those. What I am trying to do seems sooo simple, and I can't believe there isn't an easy way to do this.
What I have:
I used Visual Studio 2010 to create a simple web application (asp.net/C#) that asks the user for some info (first name, last name, email, etc.). I have a button on there called "Submit" that, when clicked, saves the entered data into a database. I have this hosted on GoDaddy (I know, I know...heh) and it works just fine. No problem here.
I created a "Facebook App" that uses the iFrame thingy so that basically I have a new tab on Facebook that displays my web app mentioned above. This works fine too. The tab is there, the web app is there, and users can enter the data and it is saved to the database. No problem here.
What I WANT:
I want the web app (the thing displayed by the facebook app) to only show the data entry part if the user currently "likes" the facebook entity. I DO NOT want to have to ask permission. I just want to know if they are a fan of the company's facebook "page" that has this app. So I need two things here, shown in my pseudo code below:
Part 1 (check if user is already a fan):
If (user is fan)
{
Show data entry area (unhide it)
}
else
{
Show "Click the like button to see more options"
}
Part 2 (listen for "like" event)
WhenLikeButtonPressed()
{
Show data entry area (unhide it)
}
I've seen stuff about "visible to connection", C# sdk, edge.create, etc. but I just can't make heads or tails of it. I don't mind putting in Javascript or PHP if someone could please give me exact, "Fan Gate for Dummies" steps. Please, I'm going crazy over here :-(
The key is is the signed_request that Facebook posts to your app when the user accesses the page. It contains the data on whether or not the user likes the page. You shouldn't need to worry about catching edge events on an actual tab FB page as it get's reloaded when the user likes/unlikes the page.
You'll need to decode the signed request with your app secret to get the like info. There are examples provided for PHP but I'm sure with a little google help you can find decode info for the signed_request for asp.net/c#.
Here's the php decode for reference:
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
and the link https://developers.facebook.com/docs/authentication/signed_request/ the like info will be contained in the page variable
I'm trying to put together a small app that will allow me to create events in Facebook. I've already got my Facebook app set up and have successfully tested a post to my feed through the application using the code below.
wc.UploadString("https://graph.facebook.com/me/feed", "access_token=" + AccessToken + "&message=" + Message);
When I try to take things to the next step, I've just hit a brick wall.
The code that I've written is here:
JavaScriptSerializer ser = new JavaScriptSerializer();
wc.UploadString("https://graph.facebook.com/me/events?" + "access_token=" + AccessToken, ser.Serialize(rawevent));
rawevent is a small object I wrote that puts together the elements of an event so I can pass it around my application.
I'm using a similar method using ser.Deserialize to parse the user data coming back from Facebook, so I believe this should work the other way too.
Setting the above code aside for a moment, I also have tried simply putting plain text in there in various formats and with differing levels of parameters, and nothing seems to work.
Is there something wrong with the way I'm approaching this? I've read over everything I could get my hands on, and very few of the samples out there that I could find deal with creating events, and when they do, they're not in C#.
I would appreciate any help on this. If you even just have a clean copy of JSON code that I can look at and see where mine should be tweaked I would appreciate it.
I have included a copy of what the ser.Serialize(rawevent) call produces below:
{"name":"Dev party!","start_time":"1308360696.86778","end_time":"1310952696.86778","location":"my house!"}
EDIT:
thanks to bronsoja below, I used the code below to successfully post an event to Facebook!
System.Collections.Specialized.NameValueCollection nvctest = new System.Collections.Specialized.NameValueCollection();
nvctest.Add("name", "test");
nvctest.Add("start_time", "1272718027");
nvctest.Add("end_time", "1272718027");
nvctest.Add("location", "myhouse");
wc.UploadValues("https://graph.facebook.com/me/events?" + "access_token=" + AccessToken, nvctest);
All the posting examples in the graph api examples in FB docs show using curl -F, which indicates values be POSTed as normal form data. Just key value pair like you did in your first example.
The error is likely due to sending JSON. If you are using WebClient you may be able to simply create a NameValueCollection with your data and use WebClient.UploadValues to send the request.
I've recently found that Facebook returns (#100) Invalid parameter when we are trying to post data when there is already a record on file with the same name. So for example, if you are creating a FriendList via the API, and the name is "foo", submitting another identical request for the same name will immediately return that error.
In testing events you probably deleted the "Dev party!" event after each test, or maybe changing the time since you don't want two events to collide. But I'm wondering if you duplicated your wc.UploadValues(...) statement just as a test if you would see that error again. You're either deleting your 'test' event or maybe changing names and didn't notice that two events with the same name might return the error.
What's really bad here is that the error comes back as a OAuthException, which seems very wrong. This isn't a matter of authentication or authorization, it's purely a data issue.
Facebook Engineers, if I'm right about how this works, it's a bug to return this error under these conditions, and this forum has many examples of related confusion. Please return more appropriate errors.