Facebook Integration using C# and asp.net core - c#

I'm starting a side project that will integrate heavily with Facebook. I'm going to use React in the front-end and it will talk to a REST ws made with asp.net core web api.
The idea is that in this API I will make the calls to Facebook.
Basically, I want to: login, get/post messages from Messenger, get/post comments and messages from a business page.
I googled a little and didn't find many resources or examples of how to do this integrations other than the Facebook documentation, that has a lot of stuff and I don't know very well where to look.
I also found this SDK for .NET but it looks a bit dated https://github.com/facebook-csharp-sdk/facebook-csharp-sdk and
So, my question is: Is reading the documentations entirely really the best solution?
If anyone could at least give me a hint where to go I'd be really thankful. Would it be better/easier to integrate with Facebook with other stack than c#/asp.net?
Also, if there's any other API, SDK or something already built in .NET that would help with that I'd be grateful.
Thanks in advance.

I am one of .net developers working with Facebook API more then 5 years and we have tried to use "Facebook SDK for C#". It has more issues then benefits. In result we end up with our own small Facebook API client. Basically it is just a "RestSharp" HTTP library, "Newtonsoft.Json" for serialization/deserialization and couple of generic functions where you supply Facebook API endpoint, and specify what class you expect back as generic parameter.
var accounts = client.Get<Accounts>("me/accounts");
var createResponse = client.Post<CreateResponse>("123456779/feed", postToCreate);

Facebook SDK for C# works great for standard .NET
https://hackerapp.com/net/
https://github.com/facebook-csharp-sdk/facebook-csharp-sdk
As for .NET Core I think you are out of luck at the moment. Unless you want to port it to .NET Core yourself.

Automated Customer Service bots are not uncommon in FB, but code is hard to find. I assume you had setup you App's domain and got it reviewed and approved by FB.
I tried to set a chat-bot with both, python and .NET, and I must say the python Api is much more complete, quick, and less buggy than the C# one. But, as far as I know, only the PyApi has integrated reactions (haven't tried them).
Therefore, you will need to do this manually by using the Facebook Api by sending direct GET/POST request triggered by your ASP.NET, or use some kind of inter-language platform such as IronPython to workaround the problem (which basically assembly the call, add the Key and secret, and CURL-it).
As final remark (not a very motivating one), there is documentation for post reactions, but not for message as you can see here (posts), and here (messenger).

You can perform a lot of the facebook operations on the client side using their javascript SDK.
https://developers.facebook.com/docs/javascript
In regards to getting up to speed on server side API calls from .NET you can check out the facebook graph api explorer. It can be helpful for discovery.
https://developers.facebook.com/tools/explorer/

In case someone is looking for this topic, I had the same needs myself. After not finding a Facebook SDK to use with .NET Core, I've created a new open source .NET Standard unofficial SDK for Facebook: https://github.com/developer82/FacebookCore

Related

Firebase Cloud Messaging with Google client library

I'm currently trying to migrate an existing server-side application which uses Firebase Cloud Messaging. To my understanding, this NuGet package is suitable for that; I have successfully referenced it in the existing C# project.
However, the documentation available here is indeed a very documented, but does not give a step-by-step example on how to initiate a call. How can I formulate a call to the API? I have done so in the past successuflly with a customized HTTP request, but don't understand how to do this with the API.
Has anyone successully used this API before and could give some insights? Although I use C#, any experience already made with a different language will be appreciated.

Facebook Apps with C# and .NET Core

I would like to develop a Facebook app. I am only familiar with C# and .NET Core. Will I experience any limitations since the business SDK is not available for .NET? I am not very familiar with Facebook development.
The Business SDK relies on the Graph API, which is also public.
Directly accessing the API is very, very common, the documentation is decent, and going that route is web-based, which works from any client you've got.
https://developers.facebook.com/docs/graph-api/
I have used the Facebook Csharp SDK recently to upload hour long videos. This is a process that runs every hour and uploads a video. During this development, I found there are bugs in the SDK and I fixed it and uploaded a pull request. But I am not sure if anyone maintains that branch. But you can get the uploaded code from my github here
https://github.com/hoquem1/facebook-csharp-sdk
If you want the parent branch, you can see where I forked it from.
You need to get your permission and Tokens properly. Directions are in facebook for developer page. For Facebook Graph Api, I used the v8.0. If you need some documentations here are some useful links below. Follow the breadcrumbs..
https://developers.facebook.com/
https://developers.facebook.com/docs/video-api/getting-started
This should get you started.

Correct approach to authenticated youtube data api (v3) requests from mobile devices (initially Android)

Scope: I am developing a mobile application using Xamarin (C#) to target both Android and iPhone (initially Android). The application logic is separated out in to a PCL (C#) where possible to ensure maximum code reuse. The application integrates with the YouTube Data API v3 for the purpose of rating retrieved videos and allowing subscription to a channel.
Background: As per the documentation (http://developer.android.com/google/play-services/auth.html) I have used the suggested approach to generate an OAuth2 token for the authorised requests from Android, using the AccountManager.getToken method and this works fine and returns a token.
The next step is to make requests using this token (let's take rating a video as an example). My initial idea was to utilise the .NET client library for the YouTube Data Api (https://developers.google.com/api-client-library/dotnet/get_started). However, it seems that this would take us through the whole authorisation process once again and would likely require a web view redirect or similar. I had hoped that there may be a way to use a token which had already been retrieved to create the credential object or create the service from directly, but it doesn't appear to be the case.
The second problem I have found with the client library is that not all of the classes appear to be referenced when adding the NuGet package, namely the GoogleWebAuthorizationBroker. Additionally, as we are in a PCL we are limited with common objects such as FileStream which is utilised in the documented examples (https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth). I did try to use this library from a non-PCL project also to confirm that it wasn't just the limited references in the PCL which were responsible (for the GoogleWebAuthorizationBroker reference issue).
The other option therefore was to look at manual construction of the URL and then posting the data to make the HTTP request ourselves. This too has met with limited success similar to the question listed here: Like video with access token on YouTube using YouTube Data API v3?, which doesn't appear to be answered (suggestion to use the client api). Is this method supported, and if so are there some documented .NET examples? This method would allow me so get the token natively (on android, iphone) and then pass it to a PCL library where I could make the requests, which would be preferable.
Question: So my question is given the scope of what I am trying to achieve here what would be the approved/suggested approach. Clearly the more I can do within the PCL the better from a code reuse point of view, but right now I'd be fairly satisfied with an approach that will actually just work for Android. If anyone has any examples of successfully making authenticated requests to the YouTube Data Api (v3) from Android that would also be useful. I feel like I've trawled through a lot of the documentation to this point over a number of days but not found anything definitive to say "this is how you should do it".
Thanks in advance for any help.
Well, I wouldn't necessarily deem this the answer to my question, however, it is the approach I have taken, so thought I would report back. I have kept the OAuth2 token generation code inside the Xamarin Android project and then pass that on to a PCL which has a repository to deal with the YouTube integration. As there are only a few calls I need to make (ratings, subscriptions and comments) I have elected to manually construct the POSTs via HttpClient and proceed that way.
Perhaps not as elegant as the client library integration but gets the job done. For reference this is made a lot easier if you use the Google OAuth Playground (https://developers.google.com/oauthplayground/) first to get the token and confirm the correct JSON for your request.
If anyone has any problems with this approach then let me know and I can post specific service calls as an example.
From what I can gather, this isn't what google-api-dotnet-client is for.
If you look at the source code (https://github.com/google/google-api-dotnet-client), you can see that GoogleWebAuthorizationBroker is defined for Windows Store, WP 8 etc.
This suggests that the library is intended for .NET clients running on Microsoft operating systems, rather than Android, iOS etc.
These might be the droids you are looking for:
https://github.com/xamarin/GooglePlayServicesComponents (Android)
https://github.com/xamarin/GoogleApisForiOSComponents
They are Xamarin wrappers around the Google SDK for each platform.
This makes sense because of the way Google APIs are called on Android. Rather than rely on a client secret which one should not embed in the application, the you register the app's signature against the "installed app" client ID. The operating system then provides this key when calling google services. You won't get that functionality in a PCL :)

Posting to my Facebook timeline from C#

Can someone please provide me with the workflow required to be able to simply post a message to my Facebook page? From what I have read, DotNetOpenAuth 4.1 does not support Facebook's OAuth 2.0 protocol? If someone has a better suggestion for an OAuth2 library, I'd like to hear it and if you can provide an example of how to post a message to a Facebook page, that'd be great!
Also, this is a Winforms application, not a Web Application.
OAuth2 clients are simple enough to write that you almost don't need a library. Try following the Facebook documentation yourself using HTTP calls in your winforms app and see if you can get it to work.
For client apps like winforms, the trickiest part can sometimes be that there isn't an obvious redirect URL.
DotNetOpenAuth 4.x does support Facebook (by implementing workarounds for FB's non-compliance with the spec).
I generally use ComputerBeacon Libarary. It is quite fluent
http://computerbeacon.net/library/facebookgraphtoolkit

OAuth C# Library for Google, Yahoo! Twitter

I'm looking for a library that will allow me to use OAuth in my ASP.NET/C# applications, such that I can authenticate users using one of the following OAuth providers
Google
Yahoo!
Twitter
I've looked at various open source libraries and find that there is one issue or another with them (some don't work at all, some work against one service not not others). I've also looked at OAuthDotNet and I must admit that I find it way too complicated to figure out how to begin using it and so I've not really tried it.
So essentially I'm looking for a simple to use library that works against the above mentioned providers (at least).
Jackie I have a blog post on this
OAuth C# Library
There is a library (including source code) and a simple sample project you can download to get started with this.
I've tested it against
1. Google
2. Twitter
3. Yahoo
4. Vimeo
You don't mention the version of OAuth you'd like to support so you should know that the library supports OAuth 1.0 revision A only and not OAuth 2.0. Most site today support OAuth 1.0 revision a.
I've kept the sample project very simple intentionally, so those starting out down this path don't have to struggle trying to figure out how to use the library. The library is not "over engineered" like I believe some libraries out there are so it is fairly simple to enhance if need be. But I suggest you attempt that only after you've familiarized yourself with the OAuth protocol.
The project in fact is an open source project hosted on Google code (link in the blog post).
Note: Due to the way Yahoo! has implemented their service it is not possible (or not simple) to test against their service from your development machine.
I hope this helps.
DotNetOpenAuth is open source library that supports OpenID, OAuth and
support for your site visitors to login with their OpenIDs.
Twitter Libraries in different languages.
Google Data client libraries are written to support client applications to access APIs.
Libraries are written in different types of languages.
If you're looking to just to Twitter then I would suggest twitterizer. It's a great library with a fairly good community and support.
http://byatool.com/c/connect-your-web-app-to-twitter-using-hammock-csharp/ (Wayback archive link.)
http://hammock.codeplex.com/ (Moved to github here: https://github.com/danielcrenna/vault/tree/master/hammock)
these link might be helpful.

Categories

Resources