所以我已经使用Facebook Unity SDK工作了几天,用它完成任务真的很难。
所以我现在面临的问题是所有事情:分享,分数API,照片共享正在管理员帐户上进行,而不是我目前正在使用的帐户。
示例
我在帐户B (我的应用上是测试用户)的游戏中获得了 1000 分的分数,然后我会尝试将该分数上传/附加到其Facebook帐户。
相反,该分数正在上传/附加到我的帐户A (该应用上的管理员帐户)。
照片,股票等也是如此。
将分数上传/附加到FB帐户的代码:
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);
}
分享图片的代码:
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);
}
示例2:[已更新]
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);
从FB Unity SDK文档开始:
的accessToken
Facebook.Unity命名空间中的一个类,包含在用户最近授权时授予您应用的访问令牌
难道它不仅仅是该用户的访问令牌,因为他授权了吗?
或者情况并非如此,用户只授权应用程序?
示例3:登录程序[已更新]
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);
}
开发人员控制台:
我一般都是Facebook SDK的新手,所以任何提示都会受到赞赏。
BTW,Facebook SDK在这个Unity项目中完全配置了他们的教程: https://developers.facebook.com/docs/unity/gettingstarted所以我的问题是为什么我通过FB应用程序发布的所有内容都转到我的管理员帐户而不是该游戏中登录的当前帐户?
另外,我想知道我的应用程序尚未获得批准,但是测试用户是否还应该工作呢?
答案 0 :(得分:0)
我设法通过这样做解决了这个问题:
1.实施登录流程(非常感谢用户@CBroe)退出如果某人已经登录并使用简单的if语句:
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");
希望这有助于某人。
<强>提示:强>