Facebook の「uid」と「accesstoken」を取得する JavaScript があります。これらの値を起動時に Ajax ActionLink に渡して、2 パラメータを受け入れる「Publish」コントローラにリダイレクトできるようにする方法はありますか。ありがとう。
<script type="text/javascript">
var uid = 0;
var accesstoken = '';
function grantPermission() {
window.FB.login(function (response) {
if (response.authResponse) {
uid = response.authResponse.userID;
accesstoken = response.authResponse.accessToken;
var postData = { facebookUID: uid, facebookAccessTok: accesstoken };
$.ajax({
url: '@Url.Action("Index","Tab")',
type: 'POST',
data: postData,
dataType: 'json',
success: function (response) {
// process the results from the controller action
// window.location.href = response.Url;
}
});
} else {
console.log('User cancelled login or did not fully authorize.');
alert('User cancelled login');
}
}, { scope: 'publish_stream' });
};
</script>
<html>
<head>
<title>Facebook Login Authentication Example</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"> </script>
</head>
<body>
<h1>Facebook Login Authentication</h1>
<br/>
@Ajax.ActionLink("Proceed", "Publish", "Tab",
new { id = "auth-loginlink" },
new AjaxOptions{UpdateTargetId = "DynamicContainer",
InsertionMode=InsertionMode.Replace,
HttpMethod="POST",
OnSuccess = "grantPermission()"
})
<br/><br/>
<div id="DynamicContainer" style="border: 1px solid #C0C0C0; padding: 1px; width: 500px; height: 400px"></div>
</body>
</html>
パブリッシュ コントローラー:
public PartialViewResult Publish( string accTok, string fullImgPath)
{
if (accTok != null && fullImgPath != null)
{
UploadPhoto(accTok, fullImgPath);
// PostToWall(accTok, fullPath);
return PartialView("BlurredPhoto");
}
return PartialView("Blank");
}