Server side facebook windows console app - c#

I'm trying to discover the possibilities with Facebook API, and want to create console application that can get all feeds of a given facebook page, where I have a user that is registered as administrator.
So the console application should be:
- Notify new post received
- Post replys to new feeds
So, after reading the Facebook API documentation, I can see that what I probably want to use, is a PAGE TOKEN, and I need a USER TOKEN before I can retrieve a page token.
I'm discovering the .net SDK, and wondering if this is usable for a server-side only app, like my console will be?? Or should I go for the more custom road, and create HTTP requests/responses based on the graph web api??
Can anyone please explain how you initialize a Page Token (including the user auth etc.), from a console application, which doesn't have any webbrowser control???
All docs and blogs I've found so far, has been targeted for ASP applications.

Related

Asp.net MVC (not core) application needs to receive a JWT from a mobile app

I have a requirement that has me a little baffled. A client has an app that allows it's customers to view it's account and billing statements. In the past the app invoked a web page on my web server built on an ASP.NET application that allowed the user to enter his credit card information and the web app processed the payment with the payment gateway.
Now the client requires that the payment page require authentication. Since the app uses JWT authentication when connecting to it's own services, the idea is to provide the JWT to the ASP.NET application so that we can verify that the call is authenticated and read some information from it. But I can't find any way for a regular ASP.NET MVC 5 web app to read a JWT that comes from somewhere else.
Has anyone seen anything like this? Anyone has any pointers for me to look at?

How to perform authentication in QuickBooks Online in installed app (NOT a web app)?

Let's say I have an installed app, a console app for example, not a web app, that I want to interact with the QBO API - I want to perform calls to QBO from my console app (but not from a web application). So I must authenticate from the console app, make a call and output in the console.
All QBO SDKs seem to ask for a callback URL or a redirect URL, i.e. a page on my server, that will perform the required leg of the OAuth 2.0 authentication. As my installed app is not a webserver, I don't have a place to host this logic. Yes, I can host a webserver to handle this logic, but I don't want to do it, this is a waste of resources for my use case (why leave an auth server on standby?). I just want to authenticate without a webserver with QBO API. Is this possible? Have I messed up my understanding of the API or of OAuth? I am at a total loss. In none of the sample code I can find a suitable example despite this being the use case that I have. (I am working with .NET / C#)
It appears that at the moment the QuickBooks Developer platform will not accommodate this (non web End-Point).
As per Intuit:
These URIs handle responses from the OAuth 2.0 server and are called
after the user authorizes the connection. URIs in this list are the
only ones to which the authorization response can be sent from the
OAuth 2.0 server. You must define at least one URI specifically for
your application's auth endpoint before you can use OAuth 2.0.
Additionally they add in a note:
Mobile- or desktop-based apps that implement OAuth 2.0 must provide a
separate SaaS layer for the Redirect URI to handle responses from the
OAuth 2.0 server.
I realize this is not what you had hoped for. Please understand, however, understand that the end-point must be a URL so as to securely return the authentication token.

Facebook authentication and GraphAPI calls in asp.net core 1.1

I am trying to create a basic solution to authenticate with Facebook on a Web Site created with Asp.net Core 1.1 and Core Identity, Visual Studio 2017.
I followed the official documentation and it works as described, but that is not the scenario that lots of people would like. After login with Facebook a second screen is shown asking to register an email (why is this if Facebook already has your email?). So i donĀ“t want to present this second screen, but to access the email already stored in Facebook, and after that be able to use the Facebook Graph API in different controllers of my application. After hours of research i was able to remove that second screen and complete the authentication flow, but also found that for Asp.net Core Microsoft doesn't have a Package to access the API( It is available for Asp.Net MVC, but not for Core), so i will need to access the API by using HttpClient and call the Rest API directly, but for doing that i will need to have inside my controllers the Access Token that Facebook issued.
How can i access, inside my controllers, the "Access Token" of the user currently authorized? I need to call the API inside my controllers. Please help.

How to authorize the Google Sheets API from a Windows Service

I've created a Windows Console Application that uses the Google Sheets API, following this link and it worked perfectly.
However when I try to build a Windows Service to do the same thing, it freezes at Authorization, presumably because the web page doesn't popup allowing me to authorize it (which makes sense for a Service).
How can I authorize it? The link says
If this fails, copy the URL from the console and manually open it in your browser
which would be great if I knew what the URL was.
Not a definite answer, but OAuth is designed rather for interactive scenarios involving users.
For service, you should create service account in google developer console and create private key for it (https://developers.google.com/identity/protocols/OAuth2ServiceAccount).
Then you have to change your code to use JWT authentication token derived from private key created in first step.
Someone already answer how to do it in C#: Is there a JSON Web Token (JWT) example in C#?

How to write a command line C# program that posts to Twitter

I'd like to write a console program in C# that posts a Tweet to Twitter. I've never used the Twitter APIs before and don't know anything about how their authentication works. I found an API library called Twitterizer, but it seems geared towards web applications and wants the user to logon with a web browser. All the API docs on Twitter's website seems geared around this scenario as well.
Is it possible to access the Twitter APIs using a console app with no web browser access? I'm perfectly fine hard coding in the name and password for the Twitter user I want to post under as well. Thanks!
Mike
You'll need to use OAuth for authenticating in twitter.
Then use regular HTTP Request to use the twitter JSON-based API.
Here you can find a good article about OAuth, Twitter and console applications.
Also take a loot at linq2twitter lib. From it's documentation;
The Twitter API is built using
Representable State Transfer (REST).
Wikipaedia defines REST as "...a style
of software architecture for
distributed hypermedia systems...",
but I'm going to be so bold as to try
to simplify what that means. In
practice, REST is a Web service
protocol built upon Hypertext Transfer
Protocol (HTTP). You use the REST Web
service by making an HTTP call with a
URL and getting text back in some
form, which is often XML or JSON. So,
if you were to write code that made an
HTTP request with the following URL:
http://api.twitter.com/1/statuses/public_timeline.xml
You would get back an XML document
with all of the Twitter statuses from
the public timeline, which is a
snapshot in time of the last 20 tweets
at the time of your request. Go ahead
and open your browser, copy and paste
the URL above into the address bar,
and see what you get back.
I couldn't find any decent information on the web on how to do this, so I decided to write my own blog post with all the details.. Enjoy!
http://blog.kitchenpc.com/2011/01/22/rise-of-the-twitterbot/
of course you can use anything to connect to Twitter via RESTful api.
you should use oauth, and set up your application in http://dev.twitter.com, then you should read all articles listed in documents, you must specify your app as Client but not Browser so user input a number to get through authentication.
you can use many libraries so that you can save your time, all are listed in the documents
and be CAREFUL, you should not use Twitter's own api console which is buggy (as i know parameters somtimes can't be parsed), you should use APIgee instead which is powerful and stable.
if you want use basic authentication, you should use api proxy (one famous is twip), if you just need only one single C# apps, you must code by yourself:
you should use given username and password to login twitter, parse cookies passed
use normal oauth to get temporaly access token url.
use cookies got from step 1, emulates form submit to allow your apps, capture PIN code
use pin code to finish oauth.
MOST IMPORTANT, you must store access token in client's machine so next time you can bypass above steps
Just wrote a Twitter Bot in C#. This is currently posting tweets to #valuetraderteam.
https://gist.github.com/sdesalas/c82b92200816ecc83af1
The API component in the GIST below is less than 500 lines, only dependency is Json.NET, you'll need to download the latest DLL for either x64 or x86 (depending on what platform you are targetting) and include as a reference in your project.
There is an example at the bottom of the page of how you can make a tweet from a console application
Hopefully this is useful to some other people out there.

Categories