2

I am using Google contacts JavaScript API. I am trying to add contacts to the gmail account of the authenticated users using the code given in the http://code.google.com/apis/contacts/docs/1.0/developers_guide_js.html#Interactive_Samples.

I am able to login and logout, but I try to create a new contact my Chrome is given an error. I have hosted the JavaScript and html file in the Amazon s3 bucket and also image.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL https://s3.amazonaws.com/googlecontacts/google_contacts.html. Domains, protocols and ports must match.

And contacts are not created.

HTML file

<!DOCTYPE HTML>
<head> <title> Google contacts </title> 
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="auth.js" > </script>
</head>

<body>
<h1> Google contacts </h1>
<img src="rss_icon.jpg" width="100" height="100" />
<input type="button" value="login" onclick="logMeIn()" />
<input type="button" value="logout" onclick="logMeOut()" />
<input type="button" value="createContact" onclick="createContact()" />

</body>
</html>

javascript file

google.load( 'gdata', '1.x' );
 
 var contactsService;

function setupContactsService() {
  contactsService = new google.gdata.contacts.ContactsService('GoogleInc-jsguide-1.0');
}

function logMeIn() {
  var scope = 'https://www.google.com/m8/feeds';
  var token = google.accounts.user.login(scope);
}


function logMeOut() {
  google.accounts.user.logout();
}

function createContact() {

/*
 * Create a contact entry
 */ 

// Create the contacts service object
var contactsService =
    new google.gdata.contacts.ContactsService('GoogleInc-jsguide-1.0');

// The feed URI that is used to create a contact entry
var feedUri = 'http://www.google.com/m8/feeds/contacts/default/full';

// Create an instance of ContactEntry
var entry = new google.gdata.contacts.ContactEntry();

// Set the name of the contact
entry.setTitle(google.gdata.Text.create('JS-Client: Create Contact'));

// Set the content of the contact
entry.setContent(google.gdata.Text.create('content info here'));

// Create an email instance
var email = new google.gdata.Email();
email.setAddress('JS-Client@domain.com');
email.setPrimary(true);
// Designate this email as the "home" email
email.setRel(google.gdata.Email.REL_HOME);

// Add the email instance
entry.setEmailAddresses([email]);

// The callback method that will be called after a successful insertion from insertEntry()
var callback = function(result) {
  PRINT('contact entry created!');
}

// Error handler will be invoked if there is an error from insertEntry()
var handleError = function(error) {
  document.getWriter='error';
}

// Submit the request using the contacts service object
contactsService.insertEntry(feedUri, entry, callback, 
    handleError, google.gdata.contacts.ContactEntry);
    }
    
    
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jeevan Dongre
  • 4,627
  • 13
  • 67
  • 129
  • I'm dealing with a similar issue (see http://stackoverflow.com/questions/7796767/is-it-possible-to-alter-one-frame-from-another-using-javascript). I figured out that if you add a delay of a few seconds before trying to alter another frame, the "about:blank" resolves to a nice-looking URL. Still got the same bug, though! – Stephen Gross Oct 17 '11 at 17:25

2 Answers2

1

Have you tried putting google.load( 'gdata', '1.x' ); in the html file?

It worked for me.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Happy Happy
  • 61
  • 1
  • 3
1

The problem was I was access https server from http server, so the protocol mis matched just changed the feedURi http://www.google.com/m8/feeds/contacts/default/full'; to https://www.google.com/m8/feeds/contacts/default/full';

Jeevan Dongre
  • 4,627
  • 13
  • 67
  • 129