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
Related
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
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
I've set my WP8 app to be RTL (right to left) and than used the Facebook c# SDK for WP8.
This is my relevant Facebook c# code:
session = await FacebookSessionClient.LoginAsync();
Now the problem is that the Facebook log in page is all mirrored and unlike the WP8 mirror the texts are also mirrored so they are sort of "backwards".
Is it a bug or can I fix it?
Got it :)
Before the line in the question I added this:
App.RootFrame.FlowDirection = System.Windows.FlowDirection.LeftToRight;
To return the app into LTR so the Facebook page will be formatted correctly and not mirrored.
In order to return it after the login had finished I added this line when I finished with the login:
App.RootFrame.FlowDirection = System.Windows.FlowDirection.RightToLeft;
It happend because the facebook login page is shown inside a Browser control so the actual text doesn't get mirrored correctly.
I guess the Facebook C# SDK people should have thought of it.. so I think we can say it sort of a bug.
Hope I helped you, future viewers!
I am trying to build a WPF C# application which requires shared data of a friend of my application user. I have tried using this query https://graph.facebook.com/[User_Id]/?fields=photos. But it do not return the array of object as mentioned in the Facebook Graph API. Although the query https://graph.facebook.com/me/?fields=photos does return pictures for the user.
I am able to retrieve the friend's cover photo by https://graph.facebook.com/[User_Id]/?fields=cover but not the photos, albums, events e.t.c . I can see that they are listed under Connection. Could anybody help ?
To access friends data, you have to ask for the appropriate permissions. Cover photos are public that's why you were able to fetch it.
Friend's Photos and Albums : friends_photos
Friend's Events: friends_events
Graph API call to receive friend's photos:
https://graph.facebook.com/User_ID/photos?access_token=your_access_token
As you're developing in C#, you might be interested in the native Facebook C# SDK.
[EDIT]
Fetching Friend's Photos and events through C# SDK:
var fb = new FacebookClient(Session["AccessToken"].ToString());
var parameters = new Dictionary<string, object>();
dynamic res = fb.Get("/User_ID?fields=photos,events");
var photoID = res.photos.data[0].id;
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/