Connect to Facebook Event Search via Google App Engine and restfb - facebook

I want to try Facebook Event search by using restfb - see http://restfb.com . My app resides on google app engine. Unfortunately I am not able to figure out what methods I need to call and how to get the right token (accessToken), which is needed for authentication and for the query.
Here is my snippet:
ScopeBuilder scopeBuilder = new ScopeBuilder();
scopeBuilder.addPermission(UserDataPermissions.USER_STATUS);
scopeBuilder.addPermission(UserDataPermissions.USER_ABOUT_ME);
String accessToken = ""; // How to get?
FacebookClient facebookClient = new DefaultFacebookClient(accessToken, Version.LATEST);
Page page = facebookClient.fetchObject("cocacola", Page.class);
System.out.println("Page likes: " + page.getLikes());

Related

How to get Access and Refresh Token while allowing google app by user

I created a google app and in Google app marketplace sdk api filled all the required details and added scopes what i required. And created a webapp in chrome developer dashboard and submitted the app for testing. While first time installing the app from marketplace it get permission from user for the scopes i added in the google app marketplace sdk api. After i click allow it will just install the app. Here how can i retrieve Accesstoken and refresh token or Authorization code while user clicks allow?
I manually get Auth code using this api call:
""https://accounts.google.com/o/oauth2/auth?client_id=CLIENTID &redirect_uri=REDIRECT_URI&scope=email+profile+https://www.googleapis.com/auth/drive&response_type=code&access_type=offline""
In the redirected uri collects access and ref token using this api call:
String accessTokenUrl = "https://accounts.google.com/o/oauth2/token";
String accessTokenUrlParameters = "client_id=" + clientId + "&client_secret=" + clientSecret + "&redirect_uri="
+ redirectUri + "&grant_type=authorization_code&code=" + code;
String accessToken = null;
String refreshToken = null;
try {
HttpClient hc = new HttpClient();
hc.setURL(accessTokenUrl);
hc.setHeader("Content-Length", "" + Integer.toString(accessTokenUrlParameters.getBytes().length));
hc.doPost("application/x-www-form-urlencoded; charset=UTF-8");
}
In this type i get both access and refresh tokens but while installing app for first time how do i get access token using that permissions and scopes. The consent screen while installing app has url like this.
https://accounts.google.com/o/oauth2/auth?client_id=1234567890-1od573nk87eq712l7suam1hu9upa8tm2.apps.googleusercontent.com&origin=https%3A%2F%2Fapis.google.com&authuser=0&login_hint=abcdefghijk#gmail.com&response_type=token&redirect_uri=postmessage&hl=en&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile
but it doesnt have redirect uri and all. How to get access token while allowing this consent screen.

How can i access facebook page likes data using ASP.NET MVC?

I have already implemented a code for accessing logged facebook user via our website for that i have created AppID and appSecret Key and it will return all data(eg.email,likes,birthday,friends).
but the problem is if logged user is only having a page then my Graph API string will not fetch result properly it only contains ID nothing else.
My code to get user details.
OAuthWebSecurity.RegisterClient(new FacebookExtendedClient(
"655618811231635",
"a05a82145a29f38a117f66ba56345081",
"email,likes",
new Func<string, object, string>(fieldsTransformer),
"email"));
and this is for getting me result.
FacebookClient facebookClient = new FacebookClient(accessToken);
facebookClient.AppId = "655618811231635";
facebookClient.AppSecret = "a05a82145a29f38a117f66ba56345081";
var getResult = facebookClient.Get<IDictionary<string, object>>("me", new { fields = this.fields });
if logged user is simple user(which having friends,groups etc) then it will work like charm but if it is user which having a Page in it then it will not display any result.

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.

Post on Facebook page wall or timeline

As FaceBook launched a new concept of pages, I created a page, but I am not able to find any C# SDK for posting on that page's timeline from code.
First you need C# SDK
you can download from here
http://csharpsdk.org/
may be you need manage_page permission to get a page access token
you can get a page access token using this Graph Request http://developers.facebook.com/tools/explorer/?method=GET&path=me%2Faccounts
after getting page access token you can post a on page wall using this code
var fb = new Facebook.FacebookClient(PageAccessToken);
var postArgs = new Dictionary<string, string>();
postArgs["link"] = "http://www.foo.com";
postArgs["name"] = "Click Here To View";
postArgs["message"] = Message;
fb.Post("[pageid]/feed/", postArgs);

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

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;