So I've been working with Facebook Unity SDK for a few days and it's a real struggle to get things done with it.
So the problem I'm facing right now is that everything: Shares,Scores API,Photo Sharing is being done on the administrator account instead of that account which I'm currently using.
Example:
I've got a score of 1000 points in my game on Account B ( Which is a test user on my app), and then I'll try to upload/attach that score to it's Facebook account.
Instead, that score is being uploaded/attached to my Account A ( which is administrator account on that app ).
Same thing follows for pictures, shares etc.
Code for uploading/attaching score to FB account:
public void WriteScoreToFBAccount()
{
Debug.Log("Trying to Upload attach Score to FB account...\n");
lg.WriteToTextUIObject("Trying to Upload attach Score to FB account...\n");
var wwwForm = new WWWForm();
wwwForm.AddField("score", 1999);
FB.API("/me/scores", HttpMethod.POST, FacebookProcessCallBack, wwwForm);
}
Code for sharing the picture:
public void TakeAScreenShot()
{
Debug.Log("Taking a Screenshot and trying to Upload it to FB...\n");
lg.WriteToTextUIObject("Taking a Screenshot and trying to Upload it to FB...\n");
ShareStatusMainWindowBackImage.SetActive(true);
var width = Screen.width;
var height = Screen.height;
var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
// Read screen contents into the texture
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
byte[] screenshot = tex.EncodeToPNG();
var wwwForm = new WWWForm();
wwwForm.AddBinaryData("image", screenshot, "InteractiveConsole.png");
FB.API("me/photos", HttpMethod.POST, FacebookProcessCallBack, wwwForm);
}
Example 2: [UPDATED]
Debug.Log("Trying to get FB friends Score...\n");
lg.WriteToTextUIObject("Trying to get FB friends Score...\n");
CurrentFacebookProcess = "GetFBScoreBoard";
string url = "https" + "://graph.facebook.com/" + AccessToken.CurrentAccessToken.UserId + "/?fields=scores%7Bapplication%2Cscore%7D&";
url += "access_token=" + AccessToken.CurrentAccessToken.TokenString;
WWWForm wwwForm = new WWWForm();
FB.API(url, HttpMethod.GET, FacebookProcessCallBack, wwwForm);
As from the FB Unity SDK docs:
AccessToken A class in the Facebook.Unity namespace containing the access token granted to your app when the user most recently authorized it
Shouldn't it be the access token just for that user because he authorized it? Or it's not the case and the user only authorized the app?
Example 3: Login procedure [ Updated]
public void LogIntoFB_Publish()
{
Debug.Log("Starting a login proccess with publish permissions...\n");
lg.WriteToTextUIObject("Starting a login proccess with publish permissions...\n");
FB.LogInWithPublishPermissions(new List<string>() { "publish_actions"}, AuthCallback);
}
public void LogIntoFB_Read()
{
Debug.Log("Starting a login proccess with read permissions...\n");
lg.WriteToTextUIObject("Starting a login proccess with read permissions...\n");
FB.LogInWithReadPermissions(new List<string>() { "public_profile", "user_games_activity", "user_friends" }, AuthRead);
}
Developers console:
I'm new to Facebook SDK in general, so any tips are appreciated.
BTW, Facebook SDK is fully configured on this Unity project by their tutorial here: https://developers.facebook.com/docs/unity/gettingstarted
So my question is why everything that I publish through the FB app goes to my administrator account instead of the current account logged in in that game?
Also, I was wondering can it be related to the thing that my App is not approved yet, but still the test users should work?
I managed to fix this problem by doing this:
1. Implementing a login flow ( Huge thanks to user @CBroe ) by Logging out if someone is already Logged in with a simple if statement:
if (FB.IsLoggedIn == true)
{
Debug.Log("[Facebook SDK]: Already LOGGED In, LOGGIN OUT...\n");
FB.LogOut();
}
else if (FB.IsLoggedIn == false)
Debug.Log("[Facebook SDK]: User is NOT LOGGED IN, NOT DOING ANYTHING...\n");
Hope this helps someone.
Tips:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.