how to make a successful connection to OneNote api using c# - c#

I read the OneNote Api Documentation https://dev.onenote.com/docs
But I don´t understand how to make a request to the OneNote API with c# web application in order to get all the pages in my OneNote.
I already got the Application Id, Application Secret Id and Redirect URL, but i don´t know where do I have to use them, because I have never done and http request and the documentation only provide the following: https://www.onenote.com/api/v1.0/me/notes/pages, so I don´t know how to send the id´s, redirect url and Authorization: Bearer.
Could you provide me the specific code to get a successful connection to OneNote API using Application Id, Application Secret Id and Redirect URL.
And the code structure to make a http request in order to get all the pages, notebooks, etc
I would appreciate if you could help me with this.

I would recommend using Microsoft Graph instead of the standalone OneNote API. Microsoft Graph includes support for OneNote. There is also an SDK for .NET available. There are also code samples for ASP.NET, UWP and Xamarin.
Before you can use the Graph API (or most any REST API for that matter), you will need to obtain an authorization token (i.e. the bearer token you referred to in your question). There are libraries available for simplifying this process. Behind the scenes, these libraries are executing an OAUTH 2.0 flow. You can read about what is going on under the covers here.

I believe the link they have on the OneNote Dev page is broken. The team has put together a public repository that contains a bunch of sample code in a myriad of languages including C#.
This is the main repo
Web API (ASP.NET Core) Repo

I believe the easiest way to understand these concepts is to look at sample code that does authentication. I recommend this sample:
https://github.com/OneNoteDev/MsGraph_OneNoteApiSampleAspNetCore
Btw - the demo is here: https://onenoteapisamplegraph.azurewebsites.net

Thank you everyone I have Checked all the links that you provided me and they were very useful, I did a connection to Microsoft Graph with the authorization token and I got access to my OneNote pages.
Thank you for your help.

Related

Accessing OneNote API using Graph? token (Azure v2.0 auth)

I am trying to remove dependence on adal.js and adal-angular.js from my project as the CMS I am using already provides support Azure authentication.
I did a bit of work to update the login provider to v2.0:
https://login.microsoftonline.com/common/oauth2/v2.0/authorize
https://login.microsoftonline.com/common/oauth2/v2.0/token
This allowed me to leverage Graph API. While I can access OneNote notebooks:
https://graph.microsoft.com/beta/me/onenote/notebooks
I find myself lacking the ability to distinguish between personal, class and staff notebooks.
https://www.onenote.com/api/v1.0/me/notes/classnotebooks
https://www.onenote.com/api/v1.0/me/notes/staffnotebooks
I am also lacking the ability to see/manage members (teachers, students, leaders, members respectively).
Prior to the update, I used an angular code example to test OneNote API and integration. But the main issue was that I had to use adal to obtain an access token. In other words, the user was forced to log in a second time despite already being signed in in order to use OneNote component. And I was hoping to do away with this extra step.
As per title, I am looking for a way to use the access/refresh token(s) obtained from Azure v2.0 auth process to silently exchange/obtain OneNote access token.
Is it even possible? And if not is there a more user-friendly workaround?
Reference:
Link to Graph OneNote endpoin
Link to OneNote ClassNotebooks endpoint
Link to OneNote StaffNotebooks endpoint
I am looking at this and think to myself why was the OneNote API not working for me before I switched to Azure v2.0? I have the right scopes too Notes.Read and Notes.Create.
ps: If I had all the necessary endpoints in Graph OneNote API I would not bother with OneNote API.
pss: In case this is of importance the front end is implemented using AngularJS which in turn leverages Graph API using Web API framework.
psss: To get a better idea of what I am talking about here a link to Graph Explorer
Sorry but the OneNote ClassNotebooks and StaffNotebooks endpoints are not yet supported in Microsoft Graph. But it is in the plans, so we will let you know when it is ready
Also, currently it is not possible to use the Azure v2.0 token for OneNote API endpoints.

Facebook Integration using C# and asp.net core

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

Access Jira API using OAuth2.0 2-legged approach in .NET

How to create access token for JIRA Rest API? Of relevant data I have
User key
Private/public key combo
Jira's Rest API Oauth example assumes 3-legged approach, and is very unclear on what the actual parameters to send are (I wish Swagger is more widely used standard!).
In more detail, I have following use-case:
When creating new employee in Web Forms (ASPX) portal application I need to create new JIRA account and assign it to project (and role inside the project).
As such I would like to use OAuth2 2-legged authentication to accomplish this. I can probably hack it with Basic Authentication, but I would really like to do it properly.
Problem arises when trying to find code examples that use this approach. .NET examples are really scarce, and even examples in other languages usually use Basic Authentication (username and password transmitted on each call) or few that use 3-legged approach.
I found AnotherJiraRestClient but looking at the code it's using RestClient nuget (this is good) but with HttpBasicAuthenticator (this is bad).
I went through all Authenticators that are on offer and OAuth2AuthorizationRequestHeaderAuthenticator looks promising but it requires me to already have access token. So that is why the question in the end is "How to create access token, using 2-legged approach?"
I already created application link on JIRA's side with this settings:
Application Type: Generic Application
Outgoing Authentication: (gives 500 server error on Jira's side... but don't think it matters as I am not using it)
Incoming Authentication: OAuth
Status: Configured
Consumer Key: TEST_JIRA_KEY
Public Key: ... (generated online private/public key combo)
Atlassian currently doesn't support OAuth 2.0, but only 1.0(a).
There is a feature request for this: https://jira.atlassian.com/browse/JRA-43171
I have made an Open Source Jira client in C#, >=.NET 4.5 and fully async (with proxy support), which is available on GitHub and as a NuGet Package. See: https://github.com/dapplo/Dapplo.Jira
Today I added OAuth 1.0a support, which I got working and use the information here for testing:
https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples/src/d625161454d1?at=default
I used the public key from that repository to setup a test link on my Jira Cloud server, and use the private key in my test case.
The code for testing is here (it's commented out, as the OAuth process opens a browser, which is bad on the test-server)
https://github.com/dapplo/Dapplo.Jira/blob/master/Dapplo.Jira.Tests/JiraOAuthTests.cs
I am still looking at a way to make the certificate/private key reading easier, but in a way this is not the job for the library itself...
If there are any questions, I guess issues on GitHub are the best way to communicate.

Using access token - calling the youTube data API C#

It's unclear to me how I can do an API request to retrieve data for the YouTube API.
I used this code (http://zavitax.wordpress.com/2012/12/17/logging-in-with-google-service-account-in-c-jwt/) to get an access token. The next step is: https://developers.google.com/youtube/v3/guides/authentication?hl=en#OAuth2_Calling_a_Google_API. I don't know how to use www.googleapis.com/youtube/v3/video?access_token=ACCESS_TOKEN in my application to retrieve data. How can I use my access token to request data from the API?
The recommendation is to use the Google APIs Client Library for .NET. As the webpage for the client library states, it's still undergoing active development and isn't as far along as the client libraries for some of the other languages. It still should be usable, though.
There are specific generated classes to use with the YouTube Analytics API and the YouTube Data API v3. You'll need to download those
Our C# sample code is unfortunately scarce, but there is one example of doing a video search. Hopefully that is enough to get you started.
To do anything with the Analytics API, and any write operations with the Data API, you'll need to be authenticated with OAuth 2. There's an explanation of how to do that in the client library docs.
The client library is maintained by a team within Google, but it's not the YouTube API team, so the best way to follow up with the maintainers with any issues you find is to use the public issue tracker.

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

Categories

Resources