Problems with leaderboard using the facebook SDK - facebook

I am trying to make a leaderboard using the facebook unity sdk(for android devices in my case) I have most of the code down and it works just fine in the editor and on phone.
I can post my score as well as retrieve it in the editor using my access token.
I can also post and retrieve my score on an android where I logged in with my id.(the one to which the app is connected)
But here's the problem:
When I try logging in with another account I can neither post my score nor can I retrieve it.
though I can get the username, profile pic of the account with which I am logged in as No.1 but the score remains 0.
Even the score of my other account isn't visible in the leaderboard.
What I deduced:
As it's mentioned on the Scores API page you require the publish_actions permission to post scores I believe this is what I am missing. But this does not explain why I am unable to see my score posted from my (developer) account.
Is it that during testing with an access token or on a mobile device using the developer or administrator account I can only see my own score using the "AppID/scores?fields=scores"?
void SetScore()
{
score = //score
var ScoreData = new Dictionary<string, string>() {{"score", score.ToString()}};
FB.API("/me/scores", Facebook.HttpMethod.POST, publishActionCallback, ScoreData);
Debug.Log ("Score data" + ScoreData);
}
void publishActionCallback(FBResult result){ Debug.Log ("ScoreUpdated!");}
public void friendsScore()
{
FB.API("/MYAPPID/scores?fields=score",
Facebook.HttpMethod.GET, CallbackFriendScores);
//HTTP GET request for the scores
}
CallbackFriendScore(FBResult result){Debug.Log ("response GET: " +result.Text);//the real callback is different but the debug can be used to recreate the same problem}
Note: I am trying to use FB.API("/me/scores", Facebook.HttpMethod.POST, publishActionCallback, ScoreData)
and FB.API("/MYAPPID/scores", Facebook.HttpMethod.GET, CallbackFriendScores) to get the scores.

Related

Facebook unity GetAppLink CallBack does not have target url

I am using Facebook Unity SDK v7.4.0 with FBAndroidSDK/4.8.2 and managed to implement deep link in a unity game for android platform. Clicking on the deep link takes me inside the game. Now I want that when the user enters the game, he has to be rewarded. But the GetAppLink callback does not have target url
Facebook.Unity.FB.GetAppLink(DeepLinkCallback);
void DeepLinkCallback(IAppLinkResult result)
{
if (result != null && !string.IsNullOrEmpty (result.TargetUrl))
{
}
else
{
Debug.Log("result is null");
}
}
I have gone through many links to try solving this.
https://developers.facebook.com/docs/unity/reference/current/FB.GetAppLink
http://answers.unity3d.com/questions/1134007/how-to-get-facebook-game-request-url.html
Deferred deep links always null in android and facebook SDK
Also deep link is enabled in the developer site, also checked if Facebook sdk is initialised properly before getting the callback
I dont know about the targetUrl but to reward the user you just have to check result.url as mentioned in the FB.GetAppLink documentation.
FB.GetAppLink(DeepLinkCallback);
void DeepLinkCallback(IAppLinkResult result) {
if(!String.IsNullOrEmpty(result.Url)) {
var index = (new Uri(result.Url)).Query.IndexOf("request_ids");
if(index != -1) {
**// ...have the user interact with the friend who sent the request,
// perhaps by showing them the gift they were given, taking them
// to their turn in the game with that friend, etc.**
}
}
}
To send custom data through a Facebook app request, you need to add that data — for example details of your gift — in the FB.AppRequest as mentioned in its documentation.
You need to get the last request id from the URL in the deep link call back and then call Facebook API to get your gift data out of it.
FB.API ("/" + recievedRequestId, HttpMethod.GET, CallbackFunction);
result.url will be null if you haven't added a scheme in Facebook SDK's unity settings.
com.example.appname is probably what you are looking to add.

How to setup Facebook App Request from Unity with Prime31 Social combo plugin?

my problem is this, when the user is asked to select friends from the list and click on Send I receive a Success state from callback but no request is reached from the people selected in the list.
My setup is this:
- my app is a native app for iOS and Android made in Unity
- my app is registered in Facebook developer portal as Game/Puzzle, I set up bundle id, package name, display name and namespace
- my app is not yet published
- I configured the Prime31 Facebook plugin with the appId given from Facebook and Display Name
I send my request like this:
public void AskLifesOnFacebook()
{
var parameters = new Dictionary<string, string>
{
//{ "app_id", "#######my_app_id_number####" },
{ "method", "apprequests" },
{ "title", "My request title" },
{ "message", "My request text" }
};
FacebookCombo.showDialog("apprequests", parameters);
}
But still the friends selector is shown up correctly on an overlay windows, I select friends and send the request but no request is received.
Am I missing something in the configuration of my app on Facebook? Do I need to pass some kind of certification?
From the same app the stream.publish is working correctly and I can publish on user walls.
The setup with Prime31 plugin and the call are correct!
You have to enable "Single Sign On" and "Deep Linking" in Facebook app parameters and add a valid itunes ID for your app (while testing you can put any valid ID, but you should create a itunes connect entry for your app and get the final ID).
When your app is a native iOS app, the users see the notifications only through the Facebook iOS app, so they are guarantee they can open iTunes or run the game.
Global notifications instead (ej: regular browser on PC) are seen if the app is in a Facebook Canvas.

AS3 FacebookDesktop Login fail with OAuthException - #2500 An active access token must be used to query information about the current user

I think this is because Facebook just made some changes to their login process.
A few days ago, my air app was working with the FacebookDesktop class from the facebook-actionscript-api. Today I opened the project, and noticed that the Facebook login screens are a little different than when I started building my app. After I type my userID and password in, I grant the app access to my public profile, friend list and photos. Then another screen comes up where I grant the app permission to post to my friends on my behalf.
Then the window closes, and I get 'OAuthException 2500 An active access token must be used to query information about the current user.'
When I sign into Facebook through a browser, I see that my app shows up under "Your Apps" but I can't log in and do anything through my app.
I'm using Adobe Flash with GraphAPI_Desktop_1_8_1.swc on OSX Lion.
Here is my code:
public function MyApp(){
FacebookDesktop.init(APP_ID, onInit);
}
protected function onInit(result:Object, fail:Object):void {
if (result) {
trace("onInit, Logged In\n");
} else {
trace("onInit, Not Logged In\n");
var permissions:Array = ["publish_stream", "user_photos"];
FacebookDesktop.login(onLogin, permissions);
}
}
protected function onLogin(result:Object, fail:Object):void {
if (result) {
trace("Logged In as:");
trace(FacebookDesktop.getSession().user.name);
} else {
trace("Login Failed");
trace('code: '+fail.error.code); //code: 2500
trace('message: '+fail.error.message); //message: An active access token must be used to query information about the current user.
trace('type: '+fail.error.type); //type: OAuthException
}
}
I get the same results when I use the FlashDesktopExample provided in the SDK (modified with my app ID of course).
Any help would be great! Thanks in advance!
I ran into this problem, too: the success URL did not have any parameters.
Cadderly82 is correct; it's a problem with secure navigation. Turning off my Facebook account's "Secure Browsing" option fixed the problem, but I didn't want to have to require users to do that.
I was able to solve this by setting ALL of the FacebookURLDefaults values to use "https://".
Now I get a valid user-access-token in the success URL; and I get valid values regardless of my facebook account's secure-browsing setting.
I have figured out the problem:
The LoginWindow class sets the token based on the uri.
This worked fine until the LOGIN_SUCCESS_URL (http://www.facebook.com/connect/login_success.html) and the LOGIN_SUCCESS_SECUREURL (https://www.facebook.com/connect/login_success.html) pages stopped including the access token in the uri.
Hence, the token is never set. Even though my app shows up under the 'Your Apps' section in Facebook after I login, my app still can't do anything without a token.
I have two solutions:
The easiest is to change the LOGIN_SUCCESS_URL and/or the LOGIN_SUCCESS_SECUREURL properties in com.facebook.graph.core.FacebookURLDefaults like the following.
beginning on line 82:
public static var LOGIN_SUCCESS_URL:String = 'http://www.facebook.com/connect/login_success.html';
public static var LOGIN_SUCCESS_SECUREURL:String = 'https://www.facebook.com/connect/login_success.html';
Change to:
public static var LOGIN_SUCCESS_URL:String = 'http://www.yourwebsite.com/';
public static var LOGIN_SUCCESS_SECUREURL:String = 'https://www.yoursecurewebsite.com/';
of course you would use your own website - not 'http://www.yourwebsite.com/'. I tried it using http://localhost/ and it worked great.
Another solution is:
Change com.facebook.graph.windows.LoginWindow with the following code. I have made some changes to my files, so please forgive me if the line numbers are different than what they are in a fresh copy of the SDK.
around line 143:
change:
vars.redirect_uri = FacebookURLDefaults.LOGIN_SUCCESS_URL;
to:
vars.redirect_uri = 'http://localhost/';
In production code, you probably want to use your own website address instead of localhost, but I used localhost for testing purposes.
Then, in the handleLocationChange function (should be around line 168) add this to the else if statements:
}else if (html.location.indexOf ('http://localhost/') == 0) {
loginCallback(getURLVariables(), null);
userClosedWindow = false;
html.stage.nativeWindow.close();
html.removeEventListener(Event.LOCATION_CHANGE, handleLocationChange);
}
As I said before, change localhost to your website address.
I hope this helps!
I was having the same problem for random users and I don't really know if it is a Facebook problem with secure navigation:
Check user properties in Facebook: Security Settings > Secure Browsing
(www.facebook.com/settings?tab=security)
For users with "disabled" state it works fine.
For users with "migration" state it gives the error.
For users with previously "enabled" state it works fine.
When I tried with users in "migration" state and changed to "disabled", it worked fine.
Then if I turned it "enabled", the "migration" state is gone and marked as "enabled", but the error it's still there.
So I guess this is the problem, but don't know how to fix it.
alot has change in a year this is what i think the answer is now
you need a token to login FacebookDesktop.getSession().accessToken
public function MyApp(){FacebookDesktop.init(APP_ID, onInit, FacebookDesktop.getSession().accessToken); }

How to make a wall post using windows phone 7 native app

I have created a native app on Windows Phone 7.
The user of the app will provide his login credentials to us when he registers as a new user. What i want to do is to give a handle of share on facebook in my app.
On clicking on the handle the selected image should be posted on to the user's wall and just display a message to the user that the image is posted successfully or not.
The problem is that facebook has not provided with a developent environment for Windows Phone 7 native apps.
I want some alternate solution to this.
thanks for the link. I had already visited the link earlier. I have implemented facebook integration in wp7. Its working properly and i am able to make wall posts.
Here's my code,
//Users clicks on Share on facebook button
private void btnFacebookPost_Click(object sender, RoutedEventArgs e)
{
//Check if access tokens are already set.
if (App.accessTokens == null)
{
GetAccessTokens();
}
else
{
//Use the access tokens to post on facebook
}
}
private void GetAccessTokens()
{
// Navigate user to facebooks login page
// if user has already authenticated your app you'll receive the access tokens directly
webBrowser.Source = new Uri("https://www.facebook.com/dialog/oauth?client_id='your app id'&redirect_uri=https://www.facebook.com/connect/login_success.html&response_type=token&scope='whatever extended permissions you require'");
}
//On The Navigated event of web browser check for access tokens
//Use the facebook c# sdk to get the access tokens from the url
void webBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
FacebookClient fbClient = new FacebookClient();
FacebookOAuthResult oauthResult;
if (fbClient.TryParseOAuthCallbackUrl(e.Uri, out oauthResult))
{
// The url is the result of OAuth 2.0 authentication
if (oauthResult.IsSuccess)
{
App.accessTokens = oauthResult.AccessToken;
}
else
{
var errorDescription = oauthResult.ErrorDescription;
var errorReason = oauthResult.ErrorReason;
}
}
else
{
// The url is NOT the result of OAuth 2.0 authentication.
}
}
Now use the access tokens with the facebook sdk for C#.net to make the wall posts or any other transactions as required.
The problem with this method is that the application user and the facebook's logged in user may be different thus making a transaction to different account.
Since the SSO for WP7 is not available this method should do the trick.

Facebook status update with PHP

My requirement was to update members status from my site, i am also thinking about displaying their friends photos and their last status update.
I have looked all over the docs and cant decide which works for my need. RESTful API, JavaScript API, FQL, XFBML, FBML, FBJS ?? whcin one works best? or best way?
It should be like, when they first go to the page,there will be nothing but a login option. when they click on it, a pop up should appear and when they are authorized, we display a text area to post update. Here, i wanted to show their friends pics too
when they came back later, they should able to post right away, must not ask for login again.
Can some one help me with the code?? I dont expect you to write everything, get the friends pic and their last update into a PHP array would be nice.
Many thanks
If u need to update users data stored at ur database so u will use the facebook API to check user signed in and get his data. i have an ifram application at facebook and i am using C# code (asp.net application) and when the user request the application i authenticate that he is signed in to facebook and check if he is already exist in my database? if not so i get his information(by using facebook API) and add the user in my data base and each time he visits the application i update his information.
With respect to his friends i get all facebook ids of the user friends and then loop these IDs and get the pic of each ID.
Download Facebook Developer Toolkit that enables u communicate with facebook and use facebook API to get user information.
hope that is will help u
Visit my application in facebook and u will see these features at the following link :
http://apps.facebook.com/hanggame/
Getting the session Key :
protected void Page_Load(object sender, EventArgs e)
{
//Facebook code for integration with facebook users:
_fbService.ApplicationKey = "Application Key";
_fbService.Secret = "Secret Key";
_fbService.IsDesktopApplication = false;
string sessionKey = (string)Session["Facebook_session_key"];
if (Session["Facebook_userId"] != null)
userId = (long)Session["Facebook_userId"];
// When the user uses the Facebook login page, the redirect back here will will have the auth_token in the query params
string authToken = Request.QueryString["auth_token"];
if (!String.IsNullOrEmpty(sessionKey))
{
_fbService.SessionKey = sessionKey;
_fbService.uid = userId;
}
else if (!String.IsNullOrEmpty(authToken))
{
_fbService.CreateSession(authToken);
Session["Facebook_session_key"] = _fbService.SessionKey;
Session["Facebook_userId"] = _fbService.uid;
Session["Facebook_session_expires"] = _fbService.SessionExpires;
}
else
{
Response.Redirect(#"http://www.Facebook.com/login.php?api_key=" + _fbService.ApplicationKey + #"&v=1.0");
}
userId = _fbService.uid;
//End of Facebook code
}