Getting Yammer Access Token in C# Console application - c#

I would like to post to my company Yammer feed from Console C# application.
Before, I created Javascript and Rest Application. But now, I do not know How to get access Token.
I tryed to use HttpWebRequest Class to Endpoint
https://www.yammer.com/dialog/oauth/?client_id=[my_client_id] &response_type=code&redirect_uri=[redirect_url]
However, Httpresponse Not contain "code".
Someone who know get access token, please tell me how to get access token.

There are a number of ways to get a sample token. You can now generate one within the screen where you created your client application. Go to https://www.yammer.com/client_applications/ and select the app you want to get a token for.
There is a link for 'Generate a developer token for this application'
For the API request you have listed I think the user would need to authenticate first then get a dialog box to accept\reject the app which would then redirect to get the code to exchange for an access token.
Docs are here:
https://developer.yammer.com/docs/oauth-2

Related

MS Graph and Azure Active Directory

Problem: How to authenticate in MS Graph using Azure AAD access token.
Current flow:
My web app has AAD configured with "Log in with AAD"
If I log into AAD my demo app is showing and if I go to https://******.azurewebsites.net/.auth/me
then I get the access_token.
What I tried:
So I tried a couple of things and this was the last, I copied the access_token as code and tried to send it, didn't work.
I'm searching for a solution to silently use the already logged-in user and call MS Graph.
The reason for the error is that you have used the wrong code. Don't try to send the access token as a code, you should request an authorization code in your browser.
https://login.microsoftonline.com/{tenant id}/oauth2/v2.0/authorize?
client_id={client id}
&response_type=code
&redirect_uri={redirect_uri}
&response_mode=query
&scope=https://graph.microsoft.com/.default
&state=12345
In addition, redirect_uri is also a required parameter.
For the already logged in user you need follow the below steps for access:
Make sure you have enable the allow access token for the register app as below
Write code to acquire access token for the for the logged in user Reference
Now you can pass this token in other successive call to get the result.

Possible to get access token on behalf on user without MS Library in Razor?

I am writing a Razor page application that get's the users data in Azure AD in the form of a HTTP GET call.
However, most of the documentation I found says to use the MS GRAPH library- is there a way to get the access token on behalf of the user with just standard HTTP?
I am not sure how to get the prompt to log into Office365 to show up from my razor pages application.
You could get access token with auth code flow.
Get an authorization code in browser:
https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
client_id={client-id}
&response_type=code
&redirect_uri={redirect_uri in azure portal}
&response_mode=query
&scope=https://graph.microsoft.com/.default
&state=12345
Get access token with the previous code:
POST https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token
client_id={client-id}
&scope=https://graph.microsoft.com/.default
&code={code from previous step}
&redirect_uri={redirect_uri in azure portal}
&grant_type=authorization_code
You will obtain the upn(The username of the user) and others after decoding the access token. If you have the required permission of MS Graph, you could also get the details of user with the API.

get campaigns info from facebook marketing api in C#

Hope I will get some help and not get marked as duplicate because spent a couple of days and still didn't find a solution for this one.
My problem is that I am working on an application that should get data from Facebook marketing API and I didn't manage to do it and am working in C#, FE is in React but would like to do this all on BE.
I created an app on Facebook, have appId, app secret, my client Id, accountId, set business manager and realize that one way to go is to go through app review but this is not an option because there are too many clients and it is not the best scenario.
Is there any other way that I implement fully user authentication, to first get authorization code and then user access token so I could get the data I need.
If I get the code over the browser I can generate a token but I would like to do it automatically over my code.
If I call https://www.facebook.com/v9.0/dialog/oauth?client_id=%7Bapp_id%7D&redirect_uri=%7Bredirect_uri%7D over httpClient it gives back some HTML text and I would need the URL it redirects you to in the browser (like on facebook - how to get a new authorization code for an access token)
And didn't find a way access token without that authorization_code

Facebook Get Status message from node C# Facebook SDK

I am trying to retrieve a message from a node (my own status message):
I am using C# Facebook SDK. My GET request is the following:
status = fb.Get("/v2.2/100006927xxxxxx_1568238173xxxxxx?fields=message")
I tested this in Graph Explorer on the development site and it works.
but in my application I get an "Unsuppported Get Request #100" error.
Is there something new because I think that worked before?
Ensure that the access token you are using on Graph API Explorer matches the one you are using in your application.
In Graph API Explorer check three calls
/app to see which app you are using
/me/permissions to see what permission is granted in the application
/me to see which app scoped user ID has been assigned
Depending on the access token and the application, the privacy level of that status might not be able available to you.
e.g. 100006927xxxxxx looks like an app scoped user ID
This will mean that only one particular application will be able to access this resource.

Is it possible to retrieve a list of Facebook friends via Server Side?

I have no idea how to start to retrieve my Facebook friends using the Facebook API. I have read the Graph API docs.
Secondly, I'm doing TDD so I want to start with my test cases.
At first, these will be integration tests because I have to integrate the real life Facebook api. After that works, I'll mock out these tests to make them unit tests.
So this is why I'm stuck. Please assume that I have a Facebook account (eg. email + password) so I can authenticate and then use the access token to get my friends.
UPDATE:
I also do have an FB App already setup (eg. app id / app secret).
The first thing that you need to do to get the list of friends, or any other api request on the behalf of the user, is to authenticate the user and get a user access token.
There are two authentication flows:
Client-Side: will result with a short lived access token (expires within a few hours) which you can then extend (on the server side) for a long lived using the new endpoint.
Server-Side: results with a long lived access token for about 60 days.
It will probably be hard to do that with TDD (at least at first), and so you might want to use one of the following facebook tools which will generate the access token for you:
Access Token Tool: gives you a list of `access tokens for all your apps bound to your own user'. Per application you get both a user token and an app token.
Graph API Explorer: Select your application at the top right corner and then click the "Get Access Token" button, then select the permissions you need and approve it, when the dialog closes you'll see the access token in the field.
With the access token that you get you can start querying the api.
To get the list of friends simply issue a request to me/fiends as explained in the Friends connection of the User object documentation.
I'm not a C# developer, but I'm aware of this C# SDK for Facebook, it should (like all other facebook SDKs) have implemented most of the work for you for sending the api requests and parsing the returned data.
From a quick look at their getting started documentation it should look something like:
var accessToken = "THE ACCESS TOKEN YOU HAVE";
var client = new FacebookClient(accessToken);
dynamic me = client.Get("me/friends");
...

Categories

Resources