get logged in user details with Facebook sdk and .Net - asp.net

I am following this link to get the logged in users details and using this code snippet below
FacebookClient fb = new FacebookClient(string_access_token_here);
dynamic myInfo = fb.Get("/me")
dynamic myExtraInfo = fb.Get("/me?fields=albums.limit(5).fields(name, photos.limit(2).fields(name, picture, tags.limit(2))),posts.limit(5)");
While I get the basic details in myInfo, in my extra info variable I only end up getting an ID
I suspect I have not crafted the URL properly. Is there something else I need to do?

You need to request the user_photos permission for your access token before you can request albums/photos.
The query itself is fine:
https://developers.facebook.com/tools/explorer?method=GET&path=me%3Ffields%3Dalbums.limit(5).fields(name%2C%20photos.limit(2).fields(name%2C%20picture%2C%20tags.limit(2)))%2Cposts.limit(5)&version=v2.0

Related

ADFS 2016 On behalf of flow : cannot get any user informations

I'm trying to implement the "on behalf of" flow in an application using ADFS 2016 as STS. As a reference, I look at this Microsoft tutorial (https://learn.microsoft.com/en-ca/windows-server/identity/ad-fs/development/ad-fs-on-behalf-of-authentication-in-windows-server). It's working as it should, I can login into my web application and then use my original access token in UserAssertion to generate a new access token with the proper audience to call my API BUT I found absolutely no way to include any user informations (sub, name, email, upn etc.) into the access token for my API, even if I set claim rules into my ADFS configurations for the API.
I checked the communication between my app and adfs using Fiddler and everything looks like the informations in the tutorial. See the screen shot of the "on behalf of" request below :
Here's the resulting access token :
Finally, here's the code I use to generate my new access token :
private async Task<string> GetAccessToken(ClaimsPrincipal user, string originalAccessToken)
{
var authority = "[authority]";
var context = new AuthenticationContext(authority, false);
string userName = user.FindFirstValue("upn");
var userAssertion = new UserAssertion(originalAccessToken, "urn:ietf:params:oauth:grant-type:jwt-bearer",userName);
var cc = new ClientCredential("https://localhost:44387/", "[client_secret]");
var result = await context.AcquireTokenAsync("https://localhost:44339/", cc, userAssertion);
return result.AccessToken;
}
Have you struggle with that scenario and if yes, did you find a way to fix this ?
Thanks
I've only used the Microsoft On Behalf Of flow with Azure AD and not ADFS, but it looks like you need to send a more detailed scope in your User Info request.
Maybe try sending 'openid profile email', to indicate that you want that type of detail, as in Section 17 of my blog post. Of course this assumes that this type of data has been registered for all users.
TROUBLESHOOTING
Looks like one of these will be the cause:
A suboptimal Microsoft library that does not allow you to send the required scope
Or ADFS 2016 perhaps lacks the scope features that work correctly in Azure AD
I would concentrate on making extra sure you are sending the correct form URL encoded request message, using a tool such as curl, Postman or a plain C# HttpClient. Here is the code I used to send the correct scope - using an open source library rather than a Microsoft one:
Sample NodeJS Code
If you can get the scope sent correctly then you should have a resolution either way:
Either you get the correct data and can update your code
Or the behaviour you want is not supported by ADFS
Good luck ...

GET request with httr does not return expected content in response

Survey Solutions is a survey website that has it's API documentation here. In that list, I'm trying to make Single assigment details to work. But I can't make it!
library(httr)
GET("demo.mysurvey.solutions/api/v1/assignments/2858",
authenticate(user = "Headquarters1", password = "Headquarters1"))
I get a successful 200 status code, but with content length = 0.
I should be able to see information about assignment 2858, viewable here: https://demo.mysurvey.solutions/Assignments/2858 (you may need to access through https://demo.mysurvey.solutions/, username and password are both Headquarters1). What am I doing wrong?
Try with https://
GET("https://demo.mysurvey.solutions/Assignments/2858",
authenticate(user = "Headquarters1", password = "Headquarters1"))
Somewhat late answer but headquarters role user doesn't have permissions to access api endpoints, you need to use credentials for the dedicated api user.

Facebook post on page

I'm using Facebook SDK 6 and Graph API to publish data from app (ASP.NET) to the page.
Firstly, my app (website) get access token using server flow as described here.
Next, it use this token to publish some text in my page:
Dim fb = New FacebookClient(accessToken)
Dim o As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
o.Add("message", "some text...")
Dim result = fb.Post("/TfdTest/feed", o)
To test it, I browse my website. I allow my site change my facebook page and give permissions (publish_stream, manage_pages). The problem is that final feed appears in "Recent Posts by Others" section:
How can I post feed from page name, not from myself???
in order to use Graph API on behalf of a Page, you need to get Page access token - see here for more details: https://developers.facebook.com/docs/authentication/pages/
Authenticate the user and request the manage_pages permission
Get the list of pages the user manages using token from (1) - https://graph.facebook.com/me/accounts?access_token=USER_ACCESS_TOKEN
Parse the list and get the PAGE token - and use it to post to the feed.

Twitterizer.TwitterUser.IsFollowing returns null

I am using Twitterizer to integrate Twitter into my ASP.NET app. After authenticating the user I am using following code to see if the authenticated user is following a specific user:
Twitterizer.TwitterUser followed = new Twitterizer.TwitterUser();
followed.ScreenName = tw_current_like;
bool? Following = followed.IsFollowing;
However Following.HasValue is always false. Am I missing something?
As I stated on the forums. Instantiating TwitterUser will not fetch any data from Twitter.
Also, the Twitter API is spotty in how/when it supplies the following indicator. You can use TwitterFriendship.Show(OAuthTokens, decimal/string) to query details about the relationship between the authenticated user and another user.

fql.query method returns empty string in asp.net

I have developed a web application 3 months ago to show facebook users by searching username. To access facebook, I have downloaded facebook dll and got application key, and secret key from facebook.
My web application was working fine and displaying records from facebook. yesterday onwards, my application is not working fine. I could not get response when I search by name.
I have tested the fql in the facebook testAPI tool online. That time I can get response. but the same fql I used in my appliation but it could not get response from facebook when I search by name. If I search by uid i can get response from facebook.
here is my code-
facebook.Components.FacebookService fb = new FacebookService();
fb.ApplicationKey = "bfeefa69afdfe81975f0d6136ace3009";
fb.Secret = "9b672d682e1d8befd06382953fc2615b";
fb.IsDesktopApplication = false;
//the below fql gives response as xml.
//select name, profile_url from user where uid = '1730923544' -I can get response for this fql.
//the below fql does not give response as xml. But it gives empty string.
//the below fql does gives us response as xml when i try in facebook testAPI.
//select name, profile_url from user where name = 'Suresh Rajan' -I couldn't get response for this fql.
string s = fb.fql.query("select name, pic_square, profile_url from user where name = 'Suresh Rajan'");
if (String.IsNullOrEmpty(str1))
Response.Write("Empty Response");
else
Response.Write(str1 + " <br />");
how to search by name in facebook fql.
thanks
r.e
Yesterday Facebook was having issues with their API that may have prevented some queries from working. Try it again today and it might work.
Here is facebook's api status page where they report any ongoing issues with the API:
http://developers.facebook.com/live_status.php
If it's still not working for you then it's likely the fix that they deployed for yesterday's issue had a bug in it. Here is a similar bug that occured a while ago that sounds just like this one: http://bugs.developers.facebook.com/show_bug.cgi?id=1359. You should open a new bug on the facebook bug tracker if that's the case since that one is old and has already been closed.

Resources