Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
6
Question by kromenak · May 06, 2012 at 06:01 PM · googlemonosecurity

Accessing Google APIs in Unity

Hey everyone,

I'm trying to send and receive data from Google's APIs in the Unity editor so, for example, I can enter data into a Google Docs spreadsheet and grab the data to display in the editor.

Google supports this through .NET, which should have made this a walk in the park. However, when I run my code to send requests to Google, they fail with a couple error variations:

 WebException: Error writing request: The authentication or decryption has failed.
 TLSException

Has anyone been able to get this sort of thing to work? Based on research into the problem so far, it seems that Mono does not like to do HTTPS requests to sources it doesn't trust (and it trusts NO sources by default). There are instructions for adding trusted sources to Mono, but I can't get them to work with Unity's version of Mono for some reason.

And unfortunately, I can't use the WWW class (which is supposed to support HTTPS) because these HTTPS requests are occurring inside of Google's DLL files.

Any thoughts? I may have to turn to SQL in the end, but Google provides such a nice editing interface, it would save me a lot of time. Thanks!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
10
Best Answer

Answer by kromenak · May 07, 2012 at 05:34 AM

Got this working after a long and bloody battle, here is how I did it!

One option for handling this particular security issue is to override the certificate policy in Mono with your own policy. Note that this is a somewhat incomplete solution because it is effectively bypassing certificate security - something NOT to be done in production, published code.

My current solution is to override the certificate policy with an extremely dumb policy that just says "Yeah, ok, you can connect". In the future, I could make this check the certificate and either accept or reject based on where the certificate is from. Here is the code:

 using System;
 using System.Net;
 using System.Net.Security;
 using System.Security.Cryptography.X509Certificates;

 public class UnsafeSecurityPolicy {

 public static bool Validator(
     object sender,
     X509Certificate certificate,
     X509Chain chain,
     SslPolicyErrors policyErrors) {
     
     //*** Just accept and move on...
     Debug.Log ("Validation successful!");
     return true;    
 }
 
 public static void Instate() {
 
     ServicePointManager.ServerCertificateValidationCallback = Validator;
 }
 }

You just need to call "Instate()" somewhere in your code before you make requests to HTTPS. This should avoid the errors I mentioned in my original question, and I was able to successfully connect to Google Docs and view some spreadsheet data.

Comment
Add comment · Show 7 · 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 lvictorino · Jul 10, 2012 at 12:29 PM 0
Share

Where can I read more about how you did to access Google APIs? I'm kind of stuck with that and I'd be curious to know more on how push some stuff on Google Spreasheets. Thanks.

avatar image kromenak · Jul 12, 2012 at 06:48 AM 1
Share

Google's API documentation is the best place to get info on accessing APIs - it is clearly written and pretty easy to follow. The trickiest part for me was the OAuth stuff (which was mainly what prompted this question). You can find the documentation here: https://developers.google.com/google-apps/documents-list/

avatar image whydoidoit · Jul 12, 2012 at 06:50 AM 0
Share

@kromenak - any chance you could post something on how that OAuth worked for you?

avatar image lvictorino · Jul 12, 2012 at 07:16 AM 0
Share

@kromenak in fact I was wondering, as @whydoidoit asked, if you could explain how you did. Anyway it would make a very interesting and useful page to have on the wiki.

avatar image kromenak · Jul 14, 2012 at 07:47 PM 5
Share

I've posted some OAuth and setup stuff as a post on my blog: http://supersegfault.com/?p=212

Hope it helps, let me know if anything needs more clarification.

Show more comments

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.

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

A node in a childnode? 1 Answer

MonoDevelop broken after updating to Unity 3.5 3 Answers

MonoDevelop Unhandled Exception. MonoDevelop will now close - Mac OSX 1 Answer

Google Sketchup models appearing badly 2 Answers

Play Services Plugin Google ID doesn't update 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