- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 WordPress 插件中使用带有 JavaScript 的登录、注册 Facebook API。我遇到了这个错误
json.stringify is not a function error at JavaScript.
问题是什么?我使用这段代码:
<div id="fb-root"></div>
<script type="text/javascript">
var button;
var userInfo;
window.fbAsyncInit = function() {
FB.init({ appId: '154333274632806',
status: true,
cookie: true,
xfbml: true,
oauth: true});
showLoader(true);
function updateButton(response) {
button = document.getElementById('fb-auth');
userInfo = document.getElementById('user-info');
if (response.authResponse) {
//user is already logged in and connected
FB.api('/me', function(info) {
login(response, info);
});
button.onclick = function() {
FB.logout(function(response) {
logout(response);
});
};
}
else {
//user is not connected to your app or logged out
button.innerHTML = 'Login';
button.onclick = function() {
showLoader(true);
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(info) {
login(response, info);
});
} else {
//user cancelled login or did not grant authorization
showLoader(false);
}
}, {scope:'email,user_birthday,status_update,publish_stream,user_about_me'});
}
}
}
// Run once with current status and whenever the status changes.
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol
+ '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
function login(response, info){
if (response.authResponse) {
var accessToken = response.authResponse.accessToken;
userInfo.innerHTML = '<img src="https://graph.facebook.com/' + info.id + '/picture">' + info.name
+ "<br /> Your Access Token: " + accessToken;
button.innerHTML = 'Logout';
showLoader(false);
document.getElementById('other').style.display = "block";
}
}
function logout(response){
userInfo.innerHTML = "";
document.getElementById('debug').innerHTML = "";
document.getElementById('other').style.display = "none";
showLoader(false);
}
//stream publish method
function streamPublish(name, description, hrefTitle, hrefLink, userPrompt){
showLoader(true);
FB.ui(
{
method: 'stream.publish',
message: '',
attachment: {
name: name,
caption: '',
description: (description),
href: hrefLink
},
action_links: [
{ text: hrefTitle, href: hrefLink }
],
user_prompt_message: userPrompt
},
function(response) {
showLoader(false);
});
}
function showStream(){
FB.api('/me', function(response) {
//console.log(response.id);
streamPublish(response.name, 'I like the articles of Thinkdiff.net', 'hrefTitle', 'http://thinkdiff.net', "Share thinkdiff.net");
});
}
function share(){
showLoader(true);
var share = {
method: 'stream.share',
u: 'http://thinkdiff.net/'
};
FB.ui(share, function(response) {
showLoader(false);
console.log(response);
});
}
function graphStreamPublish(){
showLoader(true);
FB.api('/me/feed', 'post',
{
message : "I love thinkdiff.net for facebook app development tutorials",
link : 'http://ithinkdiff.net',
picture : 'http://thinkdiff.net/iphone/lucky7_ios.jpg',
name : 'iOS Apps & Games',
description : 'Checkout iOS apps and games from iThinkdiff.net. I found some of them are just awesome!'
},
function(response) {
showLoader(false);
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
function fqlQuery(){
showLoader(true);
FB.api('/me', function(response) {
showLoader(false);
//http://developers.facebook.com/docs/reference/fql/user/
var query = FB.Data.query('select name, profile_url, sex, pic_small from user where uid={0}', response.id);
query.wait(function(rows) {
document.getElementById('debug').innerHTML =
'FQL Information: '+ "<br />" +
'Your name: ' + rows[0].name + "<br />" +
'Your Sex: ' + (rows[0].sex!= undefined ? rows[0].sex : "") + "<br />" +
'Your Profile: ' + "<a href='" + rows[0].profile_url + "'>" + rows[0].profile_url + "</a>" + "<br />" +
'<img src="' + rows[0].pic_small + '" alt="" />' + "<br />";
});
});
}
function setStatus(){
showLoader(true);
status1 = document.getElementById('status').value;
FB.api(
{
method: 'status.set',
status: status1
},
function(response) {
if (response == 0){
alert('Your facebook status not updated. Give Status Update Permission.');
}
else{
alert('Your facebook status updated');
}
showLoader(false);
}
);
}
function showLoader(status){
if (status)
document.getElementById('loader').style.display = 'block';
else
document.getElementById('loader').style.display = 'none';
}
</script>
<h3>New JavaScript SDK & OAuth 2.0 based FBConnect Tutorial | Thinkdiff.net</h3>
<button id="fb-auth">Login</button>
<div id="loader" style="display:none">
<img src="ajax-loader.gif" alt="loading" />
</div>
<br />
<div id="user-info"></div>
<br />
<div id="debug"></div>
<div id="other" style="display:none">
<a href="#" onClick="showStream(); return false;">Publish Wall Post</a> |
<a href="#" onClick="share(); return false;">Share With Your Friends</a> |
<a href="#" onClick="graphStreamPublish(); return false;">Publish Stream Using Graph API</a> |
<a href="#" onClick="fqlQuery(); return false;">FQL Query Example</a>
<br />
<textarea id="status" cols="50" rows="5">Write your status here and click 'Status Set Using Legacy Api Call'</textarea>
<br />
<a href="#" onClick="setStatus(); return false;">Status Set Using Legacy Api Call</a>
</div>
最佳答案
您可以在此处找到指向 json.stringify 代码的链接 -
如果将其添加到代码中,错误应该会消失。
或者,您可以将对此脚本的引用添加到您的代码中 -
<script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
关于javascript - json.stringify 不是 JavaScript 的函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7213424/
我从 https://github.com/douglascrockford/JSON-js/blob/master/json2.js 下载了 JSON2.js并且它没有 JSON2.stringif
我制作了一个 Stringify 协议(protocol),将实现该协议(protocol)的类型转换为字符串。 protocol Stringify { func stringify() -
在我的Reaction Native 0.70应用程序中有一些不可序列化的东西,它在上下文API中传递,以使它们可用于以下组件。以下是它的代码:。在可能需要检索不可序列化值的组件中:。但是,它在组件中
MISRA 标准不允许在宏定义中使用字符串化运算符在不使用 # 运算符的情况下实现相同概念的替代方法是什么? 最佳答案 实际上并没有任何直接的替代方案——只有变通办法。此建议规则与建议不要使用类似函数
MISRA 标准不允许在宏定义中使用字符串化运算符在不使用 # 运算符的情况下实现相同概念的替代方法是什么? 最佳答案 实际上并没有任何直接的替代方案——只有变通办法。此建议规则与建议不要使用类似函数
前言 JSON是一种轻量级数据格式,可以方便地表示复杂数据结构。JSON对象有两个方法:stringify()和parse()。在简单的情况下,这两个方法分别可以将JavaScript序列化
...使用 JSON2.js 和 JQUERY 正如您从第一张图片中看到的,对象属性 customerReport.Title 有撇号。在代码中你可以看到我正在调用 JSON.stringify()
我目前正在调查为什么 JSON.stringify() 没有正确解析我的对象。这是我试图解析为 JSON 字符串的对象: var data = [{ name: string, act
问题 大家好,有人可以帮我解决这个复杂的问题吗? :我正在使用 Spring boot v2.0.5 和 React.js v15.6.2、ReactDom v15.6.2、React Bootstr
我正在使用 Knockout.js 和 ASP.NET web ApiController 完成一个新项目。我看到的许多示例在将数据发布到服务器之前执行一些手动 JSON 序列化。此外,请求内容类型同
此宏在调用时编译: macro_rules! remote_optional { ($remote:ident with=$def:ident $def_str:expr) => {
我有一个返回对象,需要打印一些属性,但 JSON.stringify 无法识别一些属性。 例如: Object = {"Date":"Mon, 22 Jun 2015 10:56:50 GMT","C
JSON.stringify( ) 是否等同于序列化或有效序列化,或者它只是实现的必要步骤序列化? 换句话说,JSON.stringify( ) 是否足够但不需要序列化?还是必要但不充分?还是 Jav
JSON.stringify是我们经常用到的的一个方法,它主要作用是将 JavaScript 值和对象转换为字符串。如: JSON.stringify({ foo: "bar&
GCC 似乎总是在源代码中用空格扩展制表符。它保留表达式内部的空间。标准对此有何规定? 例如,c 会是什么?此示例中包含( 表示源代码文件中的乱码 \t 字符)。 #define X(a) #a co
根据this答案,JSON.parse() 的时间复杂度是 O(n) . 这是否适用于 JSON.stringify() ?似乎没有任何地方记录这一点。 最佳答案 它应该是 O(n),但是 n是被字符
connection.query( 'SELECT DeskName FROM desks WHERE stat = ?',["Booked"], function(err, rows){ if(
我们正在根据一种简单的模板格式构建动态 JSON 有效负载,该格式指示我们的有效负载应产生多少级别,例如"level1.level2"> 将产生: { "level1": [ {
我对 Node.js 和传递 JSON 数据相当陌生,但是有人可以让我深入了解为什么我不需要在其中执行 JSON.stringify 。 module.exports.getBusinessOffer
我有一个简单的 JavaScript 对象,其中包含一些设备信息,包括最后已知的地理位置(仅经度和纬度)。我正在使用 JSON.stringify 将此对象转换为 JSON,但我拥有的一个不是 boo
我是一名优秀的程序员,十分优秀!