Issue in retrieve Post from Facebook account using c# - c#

I am using Facebook Graph API to retrieve post information of user from Facebook profile.
i am writing "/me/feed?fields=id" in Graph API Explorer for retrieve post of user, it gives me list of id.
but when i try to do same thing from code in c# .net than it gives me different list of ids.
my code is like
dynamic result = client.Get("me/feed?fields=id");
i have did same thing in both but both gives me different result.
can any tell me why this happen ? where i am wrong ?
Thank you

Related

Retrieve photos from Facebook/Instagram

I am looking to retrieve photos from Facebook and Instagram for viewing in a WPF application. The idea behind is to show user existing photos and allow them to upload more using C#. A bonus would be to let the user delete photos and set their profile picture, but is not a must.
I cannot find any APIs for either Facebook or Instagram for use in a WPF application, and the ones I did find were all for web (ASP.NET/PHP).
Is there such an API and how might I go about doing this?
Looks like they have what you're looking for in the Graph API:
https://developers.facebook.com/docs/graph-api/reference/user/photos/
Facebook Graph .NET API.
Using the Facebook .NET SDK
Here is an example I whipped up, haven't tested. Should work though. It retrieves the profile picture of a user. Though if you read through the APIs you can adapt it for whatever you need.
var client = new FacebookClient("accessToken");
object taskResult = await client.GetTaskAsync("/me");
var result = (IDictionary<string, object>)taskResult;
var userId = taskResult.Where(s=>s.Key == "id").First().Value
var profilePicUrl = string.Format("https://graph.facebook.com/{0}/picture", userId);
Facebook SDK
For instagram
This link will help you embeding the instagram on a simple html webpage.
There is a button on the bottom of the post on instagram.when you click on the link a menu pops up. then click on embed
now a box pops up
just copy paste the html and you are done.
it will fetch the post for you

What are the ways to post a tweet to twitter with asp.net c#? [duplicate]

With Twitter's new OAuth interface, their API is now many times more complex than what it was. And I haven't even looked at Facebook's API yet.
What I'm wondering if there is a method that employs some higher-level, existing code or interfaces to make this a simpler task.
All I want to be able to do is initiate a Twitter tweet or Facebook share on the user's behalf and be able to control the initial text of those messages, from an ASP.NET application.
I found some similar questions on SO, but they had no answers.
EDIT: I know there are things like AddThis and ShareThis, but I need something that will give me control over the default message. It must contain a link with a code that is specific to the current user.
Twitter Integration...
For making Tweets from an ASP.NET application on users' behalf, check out Twitterizer. It's a free, open-source project for integrating with Twitter from .NET applications.
I agree that using OAuth can be a bit daunting, but the Twitterizer API wraps up most of the complexity. I've written an article on using Twitterizer in an ASP.NET application that you may be interested in: Integrating Twitter Into An ASP.NET Website Using OAuth. After reading the article, download the code sample at the end, which is a working demo showing how to use Twitterizer to post a tweet from an ASP.NET website.
Facebook Integration...
For integrating with Facebook, chcek out the Facebook Developer Toolkit. Like Twitterizer, it's an open-source, free API and should get you going in the right direction.
Happy Programming!
After looking around for a while, I found sharethis.com. They have various share buttons you can add to your site that send Twitter tweets, Facebook shares, etc.
It looks like it also supports options to control the URL, so I could modify this to include whatever URL I need.
I haven't yet figured out if I can control the default message text. I'm looking into that.
But it seems like this is probably the simplest way to accomplish what I want.
This is probably what you're after for twitter: https://twitter.com/about/resources/buttons#tweet
Let's you configure a button (or URL to redirect to) that starts the user off with some default text. The user can change the text before they post.
Don't know about facebook.
Twitter Integration:
Check this code and link/article simple and easy :
protected void btnTweet_Click(object sender, EventArgs e)
{
string oauthAccessToken = Session["twtoken"].ToString();
string oauthAccessTokenSecret = Session["twsecret"].ToString();
OAuthHelper oauthhelper = new OAuthHelper();
oauthhelper.TweetOnBehalfOf(oauthAccessToken, oauthAccessTokenSecret, txtTweet.Text);
if (string.IsNullOrEmpty(oauthhelper.oauth_error))
Response.Write("Twit Posted Successfully");
else
Response.Write(oauthhelper.oauth_error);
}
Read more how to get access token and secret key and download OAuthHelper and OAuthUtility Class below is the link -
How to post tweet on behalf of an user from asp.net using oauth authentication
Login with twitter using oauth authentication in asp.net and get access token, screen name and userid

Even with a valid access_token with right set of permissions, FacebookClient does not get ALL of the photos for given album id

Using Facebook Graph API, I am trying to get ALL of the photos from a given album ID. I tried finding it on Facebook Graph Reference site, but couldn't find any help. So here it is what I am doing.
I have a valid access token with permission of user_photos and friend_photos. I already verified that facebook debugger site. I already have the album id. And following is my URL that I am passing:
https://graph.facebook.com/<albumId>/photos?access_token=<my-valid-access-token>
I do get 4 photos, but I have 29 photos in total. Also, I don't see any cursor for "prev" or "next". So, now, I am lost. Don't know what I am missing here. Any help is appreciated. I am using Facebook SDK for .NET.
So, here is the solution that worked for me:
For facebook options, I already had "user_photos" and "friend_photos" as part of the scope. "friend_photos" is not really relevant here. I had to ADD "user_checkins" to the scope collection to get all of the photos that I had in my given album. So here it is that I am using now, and getting things working for me. Graph API Explorer was super helpful for me when I was investigatiing this.
var facebookOptions = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions{...};
facebookOptions.Scope.Add("email");
facebookOptions.Scope.Add("user_about_me");
facebookOptions.Scope.Add("user_events");
facebookOptions.Scope.Add("user_groups");
facebookOptions.Scope.Add("user_likes");
facebookOptions.Scope.Add("user_photos");
facebookOptions.Scope.Add("user_videos");
facebookOptions.Scope.Add("user_checkins");
facebookOptions.Scope.Add("user_friends");
facebookOptions.Scope.Add("user_location");
facebookOptions.Scope.Add("user_photo_video_tags");
facebookOptions.Scope.Add("user_actions.music");
facebookOptions.Scope.Add("user_activities");
app.UseFacebookAuthentication(facebookOptions);

Obtaining Photos and Albums from Facebook using C#

I'm trying to parse through and obtain my (my personal account not my app) albums from Facebook using the Facebook C# SDK. My goal is to grab the 10-12 most recent photos on my account. However, I understand I have to grab the albums first.
So, I've tried numerous things and ended up with the following url which returns a 400 Bad Request:
https://graph.facebook.com/{my_user_id}/albums?access_token={my_access_token}
The token was obtained by calling:
https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&grant_type={2}&scope={3}
Any ideas why I'd be getting the 400?
When using grant_type = client_credentials you're requesting the an app access token. This will allow you to do various administrative actions for your application. See App Login in http://developers.facebook.com/docs/authentication/.
However, when using the user-parts of the Graph Api you need to perform a User Login using the oAuth Dialog. There are different ways of doing this such as with the Javascript SDK which should be straightforward to use.
I've not found a nice way of doing this in a standalone web app using Facebook C# SDK without the Javascript SDK (it's easy in a canvas app using the CanvasAuthorize attribute).
Here's an example of how to do it i a WinForms app http://blog.prabir.me/post/Facebook-CSharp-SDK-Writing-your-first-Facebook-Application.aspx. It might work in a Asp.Net app if you could use the WebBrowser control. I've tried with WebClient but didn't have any luck.
Update
By looking at the sample here http://facebooksdk.codeplex.com/SourceControl/changeset/view/534da45e108f#Samples%2fCSMvcWebsite%2fControllers%2fHomeController.cs it looks like you should be able to use the FacebookAuthorize attribute in a standalone site.
Error code 400 means that the request was not correctly formatted. Verify that that the Final URL looks OK and try it in a browser.
The request could not be understood by
the server due to malformed syntax.
The client SHOULD NOT repeat the
request without modifications.
I.e. that you try the following https://graph.facebook.com/someuser/albums?access_token=1234 You would pre presented with the following:
{
"error": {
"type": "OAuthException",
"message": "Invalid OAuth access token."
}
}
If you provide an OK token and a real user, the result will probably look a bit different, but in your case you get a 400 because there is something wrong with the request.

Facebook Like API

I'm using facebook sdk. After the user authenticates to my application, I have his 'Likes' permission.
Can I add "like" to a product page automatically?
I'm not 100% sure on what you're asking, but here is some information which may be relevant.
Requesting a 'user_likes' permission will give you access the items a user has previously liked.
In order to programatically like something, (I believe) that entity has to exist within facebook - taken from http://developers.facebook.com/docs/reference/api/
/OBJECT_ID/likes Like the given object (if it has a /likes connection)
To do this you'll have to request the 'publish_stream' permission and then do something like:
// untested!
var app = new FacebookApp();
app.Post("OBJECT_ID/likes");
Failing that you'll have to add a like button (http://developers.facebook.com/docs/reference/plugins/like/) where the user will have to click themselves
Hope that helps :)
If I understand your question correctly, you want to add like buttons to product pages on your site. You are looking for the open graph api.
http://developers.facebook.com/docs/opengraph/

Categories

Resources