Console Application to retrieve Domain Shared Contacts (Google Apps Admin SDK) - c#

I need to write a console application to retrieve domain shared contacts (eventually update, add or delete them, too).
What I found so far is "Google Domain Shared Contacts API" should do just that, but I am a bit clueless as where to start.
I don't know how to access this API in .NET and I haven't found any examples of such a code.

As far as I can see in the documentation, Domain Shared Contacts API is not currently included in the list of Supported Google APIs for .NET .
You may, however, check in Release Notes for the Google API Client Library for .NET for announcement or updates regarding this API.
If the time comes that Domain Shared Contacts API becomes supported, you may use the following references to get started:
Easily access Google APIs from .NET
GitHub post - google-api-dotnet-client
GitHub post - google-api-dotnet-client-samples

I managed to come up with an application that sends http requests to the API, however their documentation is terrible as it lacks complete description of how exactly the requests should look like and I had to experiment a bit.

Related

How to access microsoft teams with C#, execute teams commands and get result data with C#

I'm trying to figure out how to access MS Teams or Skype commands, which are listed here, Teams commands link from within c#. Is there any way this can be done?
I can execute the commands from powershell, by importing the teams or skype module, but I want to execute the commands from within c# instead and retrieve the result data in order to process it afterwards. Is there any documentation on the subject? Or maybe somebody has done this.
EDIT: For example, this is how I would run the command "Get-CsOnlineVoiceRoute" in powershell. Its a pseudocode
Import-Module SkypeOnlineConnector
$sfbSession = New-CsOnlineSession -SessionOption (some options)
Import-PSSession #sfbSession -AllowClobber
Get-CsOnlineVoiceRoute
In the answers bellow, the guys suggest that I can use the Microsoft Graph API to do this. But can somebody show me an example call. Maybe with the command im using. How can I get the same results using the API? Or is there any documentation about what ps command relates to what api calls?
What you are looking for is to use the Microsoft Graph API. The Microsoft Graph API is a RESTful API that enables you to access Microsoft Cloud service resources (e.g. even Teams). The MicrosoftTeamsPowerShell PowerShell module is simply a convenient wrapper making API calls on your behalf for you. Since C# can also make RESTful API calls, I recommend accessing the API directly for the most seamless user experience.
Accessing and configuring Microsoft Graph API is beyond the scope of SO, and I recommend going over their Graph Quick Start page to go over some basic code samples to get you started. If you can do this type of request:
{HTTP method} https://graph.microsoft.com/{version}/{resource}?{query-parameters}
Then you are all set up to access the API. The specific API section/resource you are interested in is the Microsoft Graph Teams API. The Microsoft documentation has more info on what you might be trying to achieve.
Other things to keep in mind is, if you can't seem to do something, that while v1.0 of the API is "Production" live, the beta version has many more additional resources available and may have a feature you need. (esp. when dealing with Azure Active Directory, there are certain things that can only be done with the beta version of the API). I find the Graph Explorer to be extremely helpful in finding out exactly what type of requests I need to make before I start coding.
You can use the Graph API call to call teams commands. Could you please check this sample?

how to authenticate http requests with Google generated id-token in .net web api back-end?

I have a mobile App in Android that successfully authenticated with Google api returning id-token and also profile information. Now I need to integrate it with my login and registration which I use .net web api as backend. I found google explaind article but not with c# and nuget library and microsoft docs is little difficult to follow. It will be better if i can integrate it with Identity that visual studio provides when creating new project with user authentication generated.
thanks in advance
I resolved my confusion next day after little digging and trying>
Ok first there are two ways of authenticating with third party which i was mixing them and I got confused.
First one in which your application is web or mobile but with web view.
Second way (that I'am using) in which native android activity handle going to google api, so the resulted id-token I manually send it to my api and use this code in c# to verify, requires Google.Apis.Auth library from nuget
var Payload = await GoogleJsonWebSignature.ValidateAsync(idtoken);
See image of steps need to follow in the second way
For more info:
https://youtu.be/zZt8SFivjps
https://developers.google.com/identity/sign-in/android/start-integrating
https://developers.google.com/identity/sign-in/web/backend-auth

Connecting to Yammer from Azure Webjob

I am attempting to connect to Yammer using their .NET SDK but I am having a hell of a time managing this... The point of this exercise is to create an application in Azure which periodically - and AUTONOMOUSLY - contacts Yammer and fetches the latest messages from a specific Yammer group.
Does anyone know of the correct way to use the Yammer .NET SDK from, let's say, a console application, which does not rely on a browser (a.k.a. direct user interaction) to successfully connect via OAuth authentication?
What I have tried:
Trying to suss out what to do from the example given on .NET SDK page on developer.yammer.com, you can see under "Standard Process" an example which shows the LaunchSignIn() function with an incorrect signature! The example shows the usage as:
var authResponse = await OAuthUtils.LaunchSignIn(_clientConfig.ClientId, _clientConfig.RedirectUri, ssoEnabled);
whereas the actually signature I get from the dll is:
void OAuthUtils.LaunchSignIn(string clientId, string RedirectUri)
I'll forgive the missing ssoEnabled parameter... but the example claims the function receives a response, from which a Code is then extracted. This is, of course, the piece missing from my attempt to call:
(awaitable) Task<AuthEnvelope> AuthClient.AuthenticateAppAsync(string code)
I have scoured Google for information on the use of the Yammer .NET SDK but have come up empty handed. All manner of examples of connecting to Yammer but none are in any way relevant to the .NET API. The only thing in any way relevant that I have seen is the Yammer .NET API example uploaded, apparently, by the person who developed it, who posted the code on GitHub. I have checked this example but the two parts in it - one for Windows Phone and one for Windows "Modern App" - both rely on a Browser object being available, or something to that effect anyway. There are redirects, I'm supposed to have a RedirectUri for Yammer to direct me... So does this other example - which was the ONLY other example of using the .NET SDK that I could find.
I imagine that the reason the signature is different is because this isn't actually the same function at all. The one I am trying to use is in Yammer.Oss.Api.Utils whereas the example application doesn't even have the letters Utils together other than in the name of the class OAuthUtils... which leads me to believe that it is possibly under Yammer.Oss.Core.WinRT which, as luck would have it, I cannot reference at all... Yammer.Oss.Core only contains Collections, Constants, Extensions and Serialization.
By the way, in the announcement of the .NET SDK (see first link above), the link to documentation for the SDK leads to the Yammer Support page.
Skip the .NET SDK and just do the authorization yourself using the server-side flow. Then make the requests with HttpClient and add the Authorization header. The SDK might be helpful with some Modern Apps but it's overkill for most people. When working with the API manually the worst thing you'll have to deal with is deserializing the JSON responses with JSON.NET, or other JSON library.
You don't say what you are trying to build, but AFAIK WebJobs don't have a UI so you'll need to do the authorization from a console app or website. Then store the resulting OAuth token somewhere that the WebJob can access it. If you have need an OAuth token per user you'll need to store those in a database, but make efforts to protect them because each OAuth token provides access to their Yammer account.

Can I move a Google API implementation to a web-service?

I have an in-house CMS system written in ASP.NET C#, and I need to implement a few pages that can allow the user to access and alter their Google Analytics management settings using the Google Analytics management API.
I have added the Google.Apis.Analytics.v3 library from NuGet, and I managed to make it work using OAuth2 authentication.
However, the library installs several dependencies, and some of them are upgrading some of my existing DLL files. This is not good, because I have a lot of functionality in this solution and some other solutions that are based on these old DLLs.
Would it be possible to move all the Google API implementation into an external web-service and just call this from my CMS? That way, I would not have to upgrade the CMS's old references. The only problem that I've run into with this is that I have no idea how to use OAuth2 to allow the CMS user to use his own Google account since all this is now done in the web-service, and the authentication page from google will not open in the user's browser.
I don't think a web service will work. The user needs to be prompted for authentication with the web browser. You cant really do that from a web service and return the proper authentication.
The Google .net client lib uses the newest DLLs you may want to look into upgrading yours.

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