(T_T) sorry, I can't speak English well.
I try to delete scores for a player in unity3d
code
FB.API("/me/scores", HttpMethod.DELETE, (IGraphResult result)=>
{
Debug.Log (result.RawResult);
Debug.Log (result.Error);
}
);
result is success
but
I try to Delete All scores for the app in unity3d
code
FB.API("/1xxxxxxxxxxxxxx8/scores", HttpMethod.DELETE, (IGraphResult result)=>
{
Debug.Log (result.RawResult);
Debug.Log (result.Error);
}
);
result is fail
error message :
I/Unity(14537): {"error":{"message":"(#15) This method must be called with an app access_token.","type":"OAuthException","code":15,"fbtrace_id":"A8vi0k7aBoA"}}
how to resolve [This method must be called with an app]
I referenced this link https://developers.facebook.com/docs/games/services/scores-achievements?locale=en_US
thank you.
If you look closely it says
This method should be called with App access token
You need to provide app_access_token with request and this also requires publishing permissions.
You can have a look here to know about app access token and you can make a graph api call to get it:
GET /oauth/access_token
?client_id={app-id}
&client_secret={app-secret}
&grant_type=client_credentials
Hope this helps
Related
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.
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/"+MainActivity.ME_FBUSER_ID+"/events",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
Log.e("event",response.toString());
Toast.makeText(getActivity(), ""+response.toString(), Toast.LENGTH_SHORT).show();
}
}
).executeAsync();
returns
{Response: responseCode: 200, graphObject: {"data":[]}, error: null}
Have you set Permissions? That for you have to set user_events permission. At user login time. as like below
LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setFragment(this);
authButton.setReadPermissions(Arrays.asList("user_events", "friends_events"));
See below link for user permission:
https://developers.facebook.com/docs/facebook-login/android/permissions
https://developers.facebook.com/docs/facebook-login/permissions/#adding
You have to add permission after you can get it.
If you have done all above things and not work then you have to put app for review.
if you get Debug Message as like blow image in Graph API Explorer. You have to put app for review.
Documantation say To use the user_events permission you need to submit your app for review.
See below ScreenShot:
Your access token probably doesn't contain the user_events permission... Do you gather it during login?
See
https://developers.facebook.com/docs/facebook-login/permissions#reference-user_events
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.
I'm trying to implement a custom multiple friend selector to invite users to my game. I get the list of users calling the Graph API call InvitableFriends, and create a UI for it.
After the user selects the corresponding users, I get all the invitation tokens of the users, and make a call to an App Request as follows:
public void InviteFriends(string message, string title, FacebookDelegate callback, string[] to = null, string data = "")
{
if (FB.IsLoggedIn)
{
FB.AppRequest (message,
to,
"",
null,
null,
data,
title,
callback);
}
}
But when the call is made, I'm getting the following error:
400 Bad Request
UnityEngine.Debug:LogError(Object)
FbDebug:Error(String)
Facebook.FallbackData:JSFallback(String)
Facebook.AsyncRequestDialogPost:CallbackWithErrorHandling(FBResult)
Facebook.<Start>c__Iterator0:MoveNext()
My callback function is never called, so I can't see what the error is.
I'm using Unity 4.3 & Facebook SDK 5.1
Thanks for your help!
EDIT: I'm pretty confident that the issue is that in the TO parameter I'm passing the invite tokens that the Invitable Graph call is giving me, AND NOT THE Ids.
I tested the InteractiveConsole.cs example of friendsmash with the invitable token and it also failed. How can I get the ids of the invitable friends?
just check the url request. It may be some thing wrong with it.
or
go to https://developers.facebook.com/apps/{app-id}/app-details/
in "app Info" section, choose the proper category and sub category.
I had a similar issue.. Figured out that FB.init() has to be called before using the invitable api. Without it you would get a "400 Bad Request"
I was keeping the old access token in playerprefs and just checking it again for validity and not actually initialising FB to save load time. But eventually I had to do FB.init()
I am working with FB Unity SDK, and one constant problem i am facing is to check if FB.Init() has already been called.
Scenario:
There is a fb connect button, user clicks it.
If the user decides to cancel the dialog and click "Fb connect again"
FB sdk throws a notice saying "FB.Init() has already been called. You need to call this only once."
Here is what i am trying to do, but does'nt work
if(FB.AccessToken=="" || FB.AccessToken==null){
Debug.Log ("Fb not init(), call it");
FB.Init(OnInitComplete, null);
}else{
Debug.Log ("Facebook already init()");
OnInitComplete();
}
But, obviously this is not working since FB.Init() was called and the user cancelled it. How can i verify if FB.Init() has already been called? But i was expecting accessToken to be null?
And, do these messages effect the submission of the app? Will they be displayed in the production build?
FB.Init() shouldn't be called more than once. This is by design (because it inits Facebook GameObjects and such within Unity). Instead, do this:
FB.Init(MyOnInitComplete);
....
public void MyOnInitComplete() {
// FB.IsLoggedIn checks for the FB.AccessToken and the FB.UserId
if(!FB.IsLoggedIn){
// FB.Init() is called, but user is still not logged in.
FB.Login("<your_permissions_here>");
} else {
// User is logged in & FB.Init is called
}
}