我正在尝试使用OAuth在Gmail中获取salesforce记录。我正在阅读有关上下文小工具的信息,但无法触发OAuth请求。 我能够看到所有的javascript警报,但授权的弹出窗口没有出现。
感谢任何帮助/提示。
请在下面找到参考代码:
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="SF OAuth">
<Require feature="dynamic-height"/>
<Require feature="google.contentmatch">
<Param name="extractors">
google.com:SenderEmailExtractor
</Param>
</Require>
</ModulePrefs>
<Content type="html" view="card">
<![CDATA[
<!-- Start with Single Sign-On -->
<script type="text/javascript" src="https://gist.github.com/Sujit1987/7672590/raw/86a330515eede7c169280718decc9de4ddb494fb/jquery.js"></script>
<script type="text/javascript" src="https://gist.github.com/Sujit1987/7673430/raw/7e066e610cf98a16769c93f733efedb13fa4a5b5/jquery.popup.js"></script>
<script type="text/javascript" src="https://gist.github.com/Sujit1987/7671399/raw/f175870455f7dfe41a3dffeef7ae605138810619/forcetk.js"></script>
<script type="text/javascript">
// OAuth Configuration
var loginUrl = 'https://login.salesforce.com/';
var clientId = '******';
var redirectUri = 'https://gist.github.com/Sujit1987/7672925/raw/72a98f5a5cae641b20ad36841448f4edee6ec601/oauthcallback.html';
var proxyUrl = 'https://gist.github.com/Sujit1987/7671408/raw/ae3d9059a9fb032e0e231a8c54f00f076059f736/proxy.php?mode=native';
var client = new forcetk.Client(clientId, loginUrl, proxyUrl);
$(document).ready(function() {
alert('Hello - Inside Ready function');
$('#message').popupWindow({
windowURL: getAuthorizeUrl(loginUrl, clientId, redirectUri),
windowName: 'Connect',
centerBrowser: 1,
height:524,
width:675
});
$('#message').show();
alert('Hello - Exiting Ready Function');
});
function getAuthorizeUrl(loginUrl, clientId, redirectUri){
alert('Get Authorized Called'+loginUrl+'services/oauth2/authorize?display=popup'
+'&response_type=token&client_id='+escape(clientId)
+'&redirect_uri='+escape(redirectUri));
return loginUrl+'services/oauth2/authorize?display=popup'
+'&response_type=token&client_id='+escape(clientId)
+'&redirect_uri='+escape(redirectUri);
}
function sessionCallback(oauthResponse) {
alert('Hello - Session Call Back');
if (typeof oauthResponse === 'undefined'
|| typeof oauthResponse['access_token'] === 'undefined') {
$('#message').html('Error - unauthorized!');
} else {
client.setSessionToken(oauthResponse.access_token, null,
oauthResponse.instance_url);
client.query("SELECT Name FROM Account LIMIT 1",
function(response){
$('#message').html('The first account I see is '
+response.records[0].Name);
});
}
}
var clients = [];
matches = google.contentmatch.getContentMatches();
for(var match in matches)
{
for(var key in matches[match])
{
if(key == 'sender_email')
{
clients.push(matches[match][key]);
}
}
}
/*gadgets.window.adjustHeight(100);*/
/*function showEmail(){
document.write(clients);
}*/
</script>
<form>
<!-- <button type="button" onclick="showEmail();"> Show Sender Email </button>
<button type = "button" onclick ="getAuthorizeUrl();"> Query SalesForce </button> -->
<p id="message">Click here.</p>
</form>
]]>
</Content>
</Module>