• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by BraveVN · Apr 20, 2014 at 02:50 PM · facebookscreenshotshare

Problem when take a screenshot and share to Facebook

Edited: I build this game for Android and Window Phone platfomr.

Hello guys, In my game, when player die, there is a stat board appear with a "Share" button, what I want is when player hit the button, it capture game's screenshot and then share to Facebook. For easily understand, It work exactly like the "Share" button in Flappy Bird game.

Here is my code, I tested with a Debug.log("done") at the end of the TakeScreenshot() function and when I hit the button, I got the result: there is a word "done" in console window, the game is stopped just a bit of second (I think it's has captured the screenshot) but nothing appeared.

 if (// share button)
      callFB();
 void callFB () {
         if (!FB.IsLoggedIn) {
             FB.Login("email,publish_actions", LoginCallback);                                                                                                                                                                
         }
         else StartCoroutine(TakeScreenshot());
     }
     
     void LoginCallback(FBResult result) {                                                                                          
         FbDebug.Log("LoginCallback");                                                          
         if (FB.IsLoggedIn) {                                                                                      
             OnLoggedIn();                                                                      
         }                                                                                      
     }
     void OnLoggedIn() {                                                                                          
         FbDebug.Log("Logged in. ID: " + FB.UserId);                                            
     }
 
     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);
         Debug.Log("done");
     }
 
     private Texture2D lastResponseTexture;
     private string lastResponse = "";
     public string ApiQuery = "";
     void Callback(FBResult result)
     {
         lastResponseTexture = null;
         if (result.Error != null)
             lastResponse = "Error Response:\n" + result.Error;
         else if (!ApiQuery.Contains("/picture"))
             lastResponse = "Success Response:\n" + result.Text;
         else
         {
             lastResponseTexture = result.Texture;
             lastResponse = "Success Response:\n";
         }
     }
Comment
Kamuiyshirou
Rumisoft

People who like this

2 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BraveVN · Apr 23, 2014 at 03:22 PM 1
Share

help me please

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Kamuiyshirou · May 03, 2014 at 04:16 PM

@BraveVN, your question is important. Who can help!

Comment

People who like this

0 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BraveVN · May 05, 2014 at 01:49 AM 0
Share

Hi Kamuiyshirou, If you update your FB SDK and Unity to latest version (FB is 5.0.3 and Unity is 4.3.4 or more), you can use the TakeScreenshot() function in InteractiveConsole example. I've tested and it worked perfectly in Unity Editor. But there're some problems: First, the screenshot that you shared cannot seen by anyone except you although it's set to public. Second, I'm making a game for Window Phone and when I build to export it, a tons of errors appeared but in Android is not.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Share image with hastag 2 Answers

2 issues with Facebook Sharing in Window Phone 2 Answers

Facebook share screenshot with link. 1 Answer

facebook sdk share screen shot 0 Answers

Share Screenshot Image to Facebook with Facebook SDK 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges