2011-07-21 67 views
2

我正在使用谷歌聯繫人JavaScript API。我正在嘗試使用 http://code.google.com/apis/contacts/docs/1.0/developers_guide_js.html#Interactive_Samples中給出的代碼將聯繫人添加到已通過身份驗證的用戶的Gmail帳戶。不安全的JavaScript嘗試訪問與URL有關的框架:URL與框架空白

我可以登錄和註銷。但我嘗試創建一個新的聯繫人,我的Chrome會發生錯誤。我在亞馬遜s3存儲桶中託管了javascript和html文件,並且還包含圖像。

不安全的JavaScript嘗試訪問具有以下URL的幀:來自框架的空白URL,URL爲https://s3.amazonaws.com/googlecontacts/google_contacts.html。域,協議和端口必須匹配。

並且未創建聯繫人。

HTML文件

<!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> 

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('[email protected]'); 
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); 
    } 
+0

我正在處理類似的問題(請參閱http://stackoverflow.com/questions/7796767/is-it-possible-to-alter-one-frame-from-another-using-javascript)。我發現如果在嘗試更改另一個幀之前添加了幾秒的延遲,則「about:blank」會解析爲漂亮的URL。儘管如此,仍然有同樣的錯誤! –

回答

1

你試圖把google.load('gdata', '1.x');在HTML文件中的JavaScript文件?

它爲我工作。

相關問題