How to get AppID based on valid AccessToken and/or Facebook.FacebookClient object - facebook

I'm logged in using to my own Application using C# Facebook SDK and I can read/write/delete all data I need.
However for validation purposes I'd like to get AppID that I'm currently using (the one I used when generating login Uri) based on existing valid Access-token and Facebook.FacebookClient object.
In a similar way like in Facebook PHP SDK: $appId = Facebook->getAppId();
My access token is not like string.Concat(appId, "|", appSecret)

If I use Facebook C# Sdk I may use following code to retrieve appID I used when loging in - if at the moment I have in memmory only AccessToken available:
string myAccessToken = "...";
FacebookClient fc = new FacebookClient(myAccessToken);
IDictionary<string, object> resultContainer =
(IDictionary<string, object>)fc.Get("/app");
string retrievedAppID = resultContainer["id"] as string;
The same result can be obtained directly from Graph Api Explorer via:
https://graph.facebook.com/app
If desired Facebook application is selected at top right part of the Graph Api Explorer page.

In the Facebook C# SDK, there is no where that access_token parses(or decoded).
Naturally, Facebook C# SDK api, it takes appId from Web.Config through the FacebookSettings class.
access_token as string property of FacebookSignedRequest class.
So you may follow this link to do it yourself: https://developers.facebook.com/docs/authentication/signed_request/

You should be able to get the AppId like this:
var appId = Facebook.FacebookApplication.Current.AppId;

Related

Error in getting active access token from FB

I am having the following code to access FB graph API.
var fb1 = new FacebookClient();
dynamic result = fb1.Get( "oauth/access_token", new
{
client_id = "523408...",
client_secret = "25bd19645....",
grant_type = "client_credentials");
}
var apptoken = result.access_token;
FacebookClient fb = new FacebookClient(apptoken);
dynamic FriendList = fb.Get("me");
string t = FriendList.ToString();
Console.WriteLine(t);
Console.ReadKey();
}
But when I execute it, it is giving this error "(OAuthException - #2500) An active access token must be used to query information about the current user."
Can somebody please tell me how to get active access token using C# code?
The "User" generates the Access Token, not the server.
This page gives you a way to do it thru Facebook CSharp SDK:
I personally use Facebook JavaScript SDK for the Login and pass the Access Token to the server to make calls.
http://facebooksdk.net/docs/web/permissions/
This page gives you information about different authentication workflows:
https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.0
https://developers.facebook.com/docs/facebook-login/access-tokens/
Hope it helps.
I think access token and user (me) they're not the same person. Check Access token and user. I think we all have this problem.

Payment verification via Graph API

Im trying to make Graph API call via C#
FacebookClient fb = new FacebookClient(accessToken);
var response = fb.Get("paymentID?access_token=appID|appSecret") as IDictionary<string, object>;
I manage to get correct result with Graph API Explorer, but in C# project, I get following error message: "(OAuthException - #1151) (#1151) Requires application to be payments enabled or the phone support app"
Set access_token = App Token from https://developers.facebook.com/tools/access_token/
Check payments enabled in https://developers.facebook.com/apps/[app_id]/payments/
Are you use correct values of appID and appSecret? Seems they are incorrect (if graph says OK, and your FacebookClient in up-to-date, so, problem in token)

Facebook c# sdk get user id from signed request

I have a minor problem in facebook c# sdk
I just want to get the facebook user id without asking for permissions , just from the signed request. Up to now i have written the code below:
var current = new DefaultFacebookApplication { AppId ="***", AppSecret = "***" };
dynamic signedRequest = FacebookSignedRequest.Parse(current, Request);
var UserId = (string)signedRequest.Data.user.id;
My first question is :is that is possible? Is it possible to get the user id without oauth?
Secondly , if it is possible is the (string)signedRequest.Data.user.id statement correct?;
You cannot get the Facebook user id from the signed_request unless they've authenticated your app. It is a privacy issue.

Titanium.Facebook getting graph api access token

I'm developing an iPhone app with Appcelerator Titanium SDK 1.6.2
I am upload an photo to a users facebook album with the Titanium Facebook module, graph api.
The upload goes just fine and returns the items unique ID.
When I try to parse the JSON from the unique id I'm told i need to pass an access token, which makes sense.
How do I get the access token to be passed to the graph request url?
When I do a XHR GET request while passing Ti.Facebook.accessToken I get the following error
URL: https://graph.facebook.com/10150527948301195?access_token=t4CqzHallahfy4d7RnERrJb4ffOkQfJvrYrGEBoZ4so.epdiI6IjJGR2ZFY1ZTMHh6RlR6ZmNIcVctMHcifQ.NBRMth0vb7pXKcd8lHNz9aremoyNpvrbhz2P3zkgWJU4eHdfewOp1WruBNZS_lSDy0XM0Xu0ACry8aEmSckGJVQJxEioykrNZhT7S9mJG2OKWqMdk6ucg5IMhXMfndF9sdKwWrWb7uPKI57LzIOf5lvA
{
error = {
message = "Unsupported post request.";
type = GraphMethodException;
};
}
And if I don't pass Ti.Facebook.accessToken I'm asked for it.
I'm bound to be missing something, any help would be greatly appreciated.
see this link http://developer.appcelerator.com/blog/2011/02/facebook-module-changes-in-titanium-mobile-1-6-0.html
I think you should be using Titanium.Facebook.requestWithGraphPath(...)

Facebook C# sdk - Does the FacebookApp.Get("me") access to Facebook or just to cookie?

I'm using the Facebook c# sdk on a new project and i've a question.
In the follow code:
var app = new FacebookApp();
app.AppId = "myappid";
app.AppSecret = "theappsecretcode";
if (app.Session != null)
{
dynamic me = app.Get("me");
}
When i'm calling the method Get of FacebookApp, i'm i just accessing to the Cookie saved when i've authenticated with Facebook or i'm connecting to the Facebook and getting the values?
I'm asking because i'm saving the values of the user in a session when i authenticate with the Facebook, but if the method Get doesn't access to Facebook and just to the cookie, then i'll stop using the session and start to access to the Facebook cookie instead (i haven't understand yet if the cookie save some information about the user, but i've searched in "Watch" window in VS and i haven't found anything)
Thanks
I've examined source code of FacebookApp and FacebookAppbase classes and have found out that method Get is always accessing the Facebook (there is no any cache).