我想要将我网页中canvas做出来的图分享到FB,所以先将canvas base64后传到imgur再用
imgur的连结让他分享到FB中。而权限的部分我只有拿publish_actoin跟public_profile
但是每次shareToFB()的时后,他总会出现红红的字...而且好像非管理员连用都不能用..
请问大家有解吗?
网站:http://ototot.github.io/ToS_Card/
这是部分缩减过的code:
function shareToFB () {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
//已登入且和app连结
var uid = response.authResponse.accessToken;
accessToken = response.authResponse.accessToken;
init();
} else if (response.status === 'not_authorized') {
//已登入但未与app连结
login();
} else {
//未登入
login()
}
});
}
function login() {
FB.login(function(response) {
if (response.authResponse) {
init()
}else{
//somethibg
}
}, { scope: 'public_profile,publish_actions' });
}
function init () {
var link = ""
var imgURL = ""
$.ajax({
url: 'https://api.imgur.com/3/image',
headers: {
'Authorization': 'Client-ID e51ef6bcc76b94e'
},
type: 'POST',
data: {
'image':
get("output").toDataURL("image/png").replace("data:image/png;base64,","")
},
datatype: 'JSON',
success: function(req) {
imgURL = req.data.link
link = req.data.deletehash
FB.api('/me/photos', 'post', {
access_token: accessToken,
message: get("pd").value,
url:imgURL
}, function(response){
if (!response || response.error) {
//Something
} else {
//something
}
});
}
});
}window.fbAsyncInit = function() {
FB.init({
appId: XXXXXXXX,
status: true,
cookie: true,
xfbml: true,
oauth: true,
version: 'v2.0'
}
);
}
function shareToFB () {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
//已登入且和app连结
var uid = response.authResponse.accessToken;
accessToken = response.authResponse.accessToken;
init();
} else if (response.status === 'not_authorized') {
//已登入但未与app连结
login();
} else {
//未登入
login()
}
});
}
function login() {
FB.login(function(response) {
if (response.authResponse) {
init()
}else{
//somethibg
}
}, { scope: 'public_profile,publish_actions' });
}
function init () {
var link = ""
var imgURL = ""
$.ajax({
url: 'https://api.imgur.com/3/image',
headers: {
'Authorization': 'Client-ID e51ef6bcc76b94e'
},
type: 'POST',
data: {
'image':
get("output").toDataURL("image/png").replace("data:image/png;base64,","")
},
datatype: 'JSON',
success: function(req) {
imgURL = req.data.link
link = req.data.deletehash
FB.api('/me/photos', 'post', {
access_token: accessToken,
message: get("pd").value,
url:imgURL
}, function(response){
if (!response || response.error) {
//Something
} else {
//something
}
});
}
});
}window.fbAsyncInit = function() {
FB.init({
appId: XXXXXXXX,
status: true,
cookie: true,
xfbml: true,
oauth: true,
version: 'v2.0'
}
);
}
function shareToFB () {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
//已登入且和app连结
var uid = response.authResponse.accessToken;
accessToken = response.authResponse.accessToken;
init();
} else if (response.status === 'not_authorized') {
//已登入但未与app连结
login();
} else {
//未登入
login()
}
});
}
function login() {
FB.login(function(response) {
if (response.authResponse) {
init()
}else{
//somethibg
}
}, { scope: 'public_profile,publish_actions' });
}
function init () {
var link = ""
var imgURL = ""
$.ajax({
url: 'https://api.imgur.com/3/image',
headers: {
'Authorization': 'Client-ID e51ef6bcc76b94e'
},
type: 'POST',
data: {
'image':
get("output").toDataURL("image/png").replace("data:image/png;base64,","")
},
datatype: 'JSON',
success: function(req) {
imgURL = req.data.link
link = req.data.deletehash
FB.api('/me/photos', 'post', {
access_token: accessToken,
message: get("pd").value,
url:imgURL
}, function(response){
if (!response || response.error) {
//Something
} else {
//something
}
});
}
});
}