'publish actions' permission is not require for screenshot posting? - facebook

Sorry. I can not speak English well.
I'm developing a small game using UNITY3D and Facebook UNITY SDK
I have submitted a review to facebook team for publish_actions permission.
(My game post a screenshot to user's timeline.)
And I received this result message .
"Your app experience does not need the requested permission."
I'm using Facebook SDK example code for screenshot function.
https://developers.facebook.com/docs/unity/reference/current/FB.API
private IEnumerator TakeScreenshot()
{
yield return new WaitForEndOfFrame();
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", Facebook.HttpMethod.POST, Callback, wwwForm);
}
'Screenshot button' is pressed, dialog does not appear.
when I tried screenshot function without permission, this function did not working
What's wrong?

The docs at
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/photos/#pubperms
clearly state that you need the publish_actions permission to be able to upload photos for the User.

Related

Imaged loaded via new WWW doesn't display in a build, but it does in the player

I'm loading a .jpeg file in at runtime from disk, it works absolutely fine in the player but when I build the project the texture being loaded in via WWW doesn't display - no errors. It suggests a format issue, but like I said it renders as expected in the player:
Unit doc: https://docs.unity3d.com/ScriptReference/WWW.LoadImageIntoTexture.html
private IEnumerator SetMaterialImage(string path)
{
Texture2D tex;
tex = new Texture2D(4, 4, TextureFormat.RGB24, false, true);
WWW www = new WWW(path);
if (!string.IsNullOrEmpty(www.error))
{
Debug.Log("ERROR REDNERING IMAGE --- " + www.error);
}
while (!www.isDone) yield return null;
if (www.isDone)
{
Debug.Log("WWW,ISDONE = TRUE");
Shader shader = Shader.Find("Standard");
www.LoadImageIntoTexture(tex);
GetComponent<Renderer>().material.mainTexture = tex;
GetComponent<Renderer>().material.shader = shader;
}
}
Edit: please don't suggest the Resources folder - this particular application must load from disk
I was unable to locate any Unity documentation that explains why this scenario differed between Player and Build, however I was able to confirm that:
GetComponent<Renderer>().material.mainTexture = tex;
Renderer>().material.shader = shader;
Should have been declared in the opposite order:
Renderer>().material.shader = shader;
GetComponent<Renderer>().material.mainTexture = tex;
Edit: Credit #Programmer 'The reason that code work in the Editor is because the Editor remembers which Shader or Texture is assigned to a material. So, when you change the shader, it uses the old texture'

Unity3d Issue NGUI UITexture/Facebook www Profile Pic

Having small issue here with Unity and NGUI. NGUI has UITexture as its main texture such as Unity has GUITexture.
I sent a request to facebook to get the users profile image which sends back a perfect url which if I put in the browser works fine.
My issue is taking that Texture2D (Facebook API does it as a Texture2D) and putting it on my UITexture. For some reason it just does not take it correctly. I keep getting a null value for it. I am also using Mobile Social as well from the asset store any help, helps.
Here is my snippet of code.
private void UserDataLoaded(FB_Result result)
{
SPFacebook.OnUserDataRequestCompleteAction -= UserDataLoaded;
if (result.IsSucceeded)
{
Debug.Log("User Data Loaded!");
IsUserInfoLoaded = true;
string FBNametxt = SPFacebook.Instance.userInfo.Name;
UILabel Name = GameObject.Find("FBName").GetComponent<UILabel>();
Name.text = FBNametxt;
Texture2D FBLoadTex = SPFacebook.Instance.userInfo.GetProfileImage(FB_ProfileImageSize.normal);
FBGetProfile.GetComponent<UITexture>().mainTexture = FBLoadTex != null ? FBLoadTex : PlaceHolderImg;
}
else {
Debug.Log("User data load failed, something was wrong");
}
}
The placeholder image is just a already selected image used if the fbprofile pic does is null. Which I keep getting.....
It's possible you're looking for RawImage which exist for this purpose
http://docs.unity3d.com/Manual/script-RawImage.html
Since the Raw Image does not require a sprite texture, you can use it to display any texture available to the Unity player. For example, you might show an image downloaded from a URL using the WWW class or a texture from an object in a game.
Use Unity.UI and use that feature.
Add "Ngui Unity2d Sprite" component instead of UiTexture to your profile picture in editor and use below code in your Fb callback
private void ProfilePicCallBack (FBResult result)
{
if (result.Error != null) {
Debug.Log ("Problem with getting Profile Picture");
return;
}
ProfileImage.GetComponent<UI2DSprite> ().sprite2D = Sprite.Create(result.Texture, new Rect(0,0,128,128), new Vector2(0,0));
}
there might be an another way to do this. but this worked for me

How to use download picture in WebGL?

I want to download a jpg, and use it in my game.
This is my code, and this code works very well in unity Editor and unity web player. But when I build a WebGL, it just show a picture with a "?". Is there something wrong?
This the "?" picture
IEnumerator TestDownPNG() {
string url = "https://xxxx/test_bg.jpg";
WWW www = new WWW(url);
yield return www;
Texture2D texture2d = www.textureNonReadable;
Sprite sprite = Sprite.Create (texture2d, new Rect(0, 0, texture2d.width, texture2d.height), new Vector2(0.5f, 0.5f));
objectA.GetComponent<SpriteRenderer>().sprite = sprite;
}

Advise on how to edit text posted to facebook with FB.API of Unity Facebook SDK

I created a Game on Unity3D and I am in the process of adding support for Facebook. What I would like to achieve is the users posting a screenshot of the game showing the score.
I succeeded technically, but Facebook rejected my game because the text message that is posted along with the picture is pre-filled, and that violates section 2.3 of their Platform Policy.
Here is a pice of code found on the Example that comes with Facebook SDK for Unity in which I based mine... I guess this sample code created by Facebook does not comply either.
private IEnumerator TakeScreenshot()
{
yield return new WaitForEndOfFrame();
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");
wwwForm.AddField("message", "herp derp. I did a thing! Did I do this right?");
FB.API("me/photos", Facebook.HttpMethod.POST, Callback, wwwForm);
}
So before investing a lot of time implementing a text editor in Unity3D for the sole purpose of posting to Facebook, I am looking for advise.
First, is there a way I can get my app approved without creating a text editor at all?
1) If I just post the screenshot will Facebook approve my game? Or I still will get rejected for posting a pre-filled image?
2) Is there a way to achieve this without creating an App on Facebook and requesting approval for "publish_actions" permission? maybe passing the image to the Facebook App?
If there is no option and I must create a text editor with a touch keyboard to allow the user to edit the message, what would be the best way to do it keeping compatibility for iOS, Android and Windows Phone 8.
I did manage to get approved by Facebook, but believe me, there is no shortcut. You need to offer a way for the user to preview what is being posted, and edit the text before submitting it.
In the end it was not that hard, thanks to the GUI controls. You can use GUI.DrawTexture to show a preview of the screen captured. You can use GUI.TextField to allow the user to edit the message and use GUI.Button to show "Share" and "Cancel" buttons. Put all this code on the OnGUI() method.
You can even add the profile picture next to the TextBox so the user gets the social feeling and also so the user knows which user is posting. During my tests I noticed the App cache the Facebook tokens and even if you change the Facebook user on the phone and Facebook App, my game kept using the original user when posting.
Since the question focus on how to edit the Text and not on how to interact with Facebook I will post the GUI code here, but not the facebook code which is similar to what I previously posted.
The code assumes you have all the textures mentioned and that the user already agreed to give permissions for: "public_profile,publish_actions".
The code also uses a Boolean named socialAskMessage that you need to set true in order to show the user interface. Also when you set socialAskMessage it is advisable that you ignore all other user input. In my game I reactivate all user input after 0.5 seconds in another function named DelayedCanClick(). The method to actually post to facebook resides inside social.PublishOnFacebook() that I do not present here.
void OnGUI() {
//GUI.Label(new Rect(10, 10, 100, 20), "Res" + Screen.width + " x " + Screen.height);
if (socialAskMessage)
{
//Background
GUI.DrawTexture(new Rect(0f, 0f, Screen.width, Screen.height / 3f),socialBackground,ScaleMode.StretchToFill);
//Screenshot
GUI.DrawTexture(new Rect(margin, margin, Screen.width/3f - margin*2f, Screen.height / 3f - margin*2f),screenshot,ScaleMode.ScaleToFit);
//Profile Picture
if (profilePicture != null)
GUI.DrawTexture(new Rect(Screen.width*7f/10f,Screen.height/9f,83f*Screen.width/960f,83f*Screen.width/960f), profilePicture);
//Hanlde Enter/Return event/Share Button
if (GUI.Button(new Rect(Screen.width*8f/10f,Screen.height/9f,83f*Screen.width/960f,83f*Screen.width/960f),shareButtonTexture,emptyGUIStyle)
||
( (Event.current.type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) )
)
{
audioTac.Play();
if (socialMessage.StartsWith("Write"))
socialMessage = "";
else if (socialMessage.Length > 0)
{
socialAskMessage = false;
social.PublishOnFacebook();
}
else //If empty
socialMessage = "Write a comment...";
}
//Hanlde ESC/Cancel Button
if (GUI.Button(new Rect(Screen.width*9f/10f,Screen.height/9f,83f*Screen.width/960f,83f*Screen.width/960f),cancelButtonTexture,emptyGUIStyle)
||
( (Event.current.type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Escape) )
)
{
audioTac.Play();
socialAskMessage = false;
}
if (socialAskMessage) //If still needed, show it
{
GUI.skin.textField.fontSize = 22;
GUI.skin.textField.fontStyle = FontStyle.Bold;
GUI.skin.textField.wordWrap = true;
GUI.skin.textField.focused.textColor = Color.white;
GUI.SetNextControlName("socialTextArea");
socialMessage = GUI.TextField(new Rect(Screen.width/3f, margin, Screen.width/2.75f - margin*2f, Screen.height / 3f - margin*2f), socialMessage, 200);
GUI.FocusControl("socialTextArea");
if ((socialMessage.Length == 17 || socialMessage.Length == 19) && socialMessage.StartsWith("Write a comment"))
socialMessage = socialMessage.Replace("Write a comment","").Replace(".","");
}
else //Dont show it anymore, reactivate click
{
StartCoroutine(DelayedCanClick());
}
}
}

Posting screenshot through Facebook SDK for Unity

I have a problem with posting screenshot to FB. Connection is not the problem because I collect, deserialize and show my fb data. Post score and message to friend work fine but I cannot manage to post a shot from my phone. I am using Eclipse for debugging but I don't get any errors. My code look like this:
`
IEnumerator TakeScreenShot()
{
//coroutine because I want to wait until end of the frame for shot
yield return new WaitForEndOfFrame();
//create new texture that will be my screenshot
Texture2D tex = new Texture2D(Screen.width,Screen.height,TextureFormat.RGB24, false);
// read pixels from screen
tex.ReadPixels(new Rect(0,0,Screen.width,Screen.height),0,0);
//and apply them to texture
tex.Apply();
// now we have screenshot
// now we need to encode texture to array of bytes
byte[] buffer = tex.EncodeToPNG();
//so we can save it to storage
// System.IO.File.WriteAllBytes(Application.dataPath + "/screenshots/screen/screen" + ".png", buffer);
//or to convert it to string for posting to facebook
string s = Convert.ToBase64String(buffer);
//????? maybe my string format is not correct
var query = new Dictionary<string, string>();
query["photos"] = s;
FB.API("me?fields=photos",Facebook.HttpMethod.POST, delegate (string r) { ; }, query);
}
`
when I go to GraphExplorer and paste command "me?fields=photos" I get nothing. It means function did nothing. I forgot to say that i granted permission for user_photos. This is frustrating. I have lost three days on problem that looked trivial, and yet no solution in sight. I will appreciate any suggestions.
Right now there's no easy way to handle this through FB.API since it takes in a Dictionary<string, string>.
However FB.API() is really just a wrapper around Unity's WWW class. You can call the graph endpoints at graph.facebook.com and pass in the byte[] buffer = tex.EncodeToPNG() as a param in WWWForm().
UPDATE: FB.API() has been updated in version 4.3.3 to support WWWForm as well. You can now upload photos via that method now.