我正在使用 HTML5 Canvas 生成图片并使用 /me/photos
端点将其发布到用户的时间轴,如下所示:
var canvas = self.canvas[0],
// get a data url of the canvas contents, like data:image/png;base64,abcdefghijk
dataUrl = canvas.toDataURL('image/png'),
// get the base64 data without the url portion, like abcdefghijk
data = dataUrl.substring(dataUrl.indexOf(',') + 1),
// get the raw binary data
rawData = atob(data);
// create an array buffer of the raw data
var buffer = new Uint8Array(rawData.length);
for (var i = 0; i < rawData.length; ++i)
{
buffer[i] = rawData.charCodeAt(i);
}
// create a blob out of the array buffer, which we're going to send in the form data
var blob = new Blob([ buffer ], { type: 'image/png' })
// create the form data that we're going to send
var formData = new FormData();
//formData.append('access_token', response.authResponse.accessToken);
formData.append('source', blob);
formData.append('message', 'Test message');
formData.append('privacy', '{"value": "ALL_FRIENDS"}');
// send via ajax
$.ajax({
url: 'https://graph.facebook.com/me/photos?access_token=' + response.authResponse.accessToken,
type: 'POST',
data: formData,
processData: false,
contentType: false,
cache: false
}).done(function(data, textStatus, jqXHR) {
console.log('posted image', data, textStatus);
}).fail(function(jqXHR, textStatus, errorThrown) {
console.log('failed to post image', textStatus, errorThrown);
});
这有点管用。图片将上传到为应用程序创建的相册中。但是图片设置了“Only Me”权限,需要审批:
如何控制此权限并让图片直接发布到用户的时间线?也就是说,图片需要有“好友”权限,用户不应该批准相册中的图片。
我已经尝试将 privacy
参数设置为 ALL_FRIENDS
(参见上面的代码),但这似乎没有任何效果。此外,当我通过登录对话框授权应用程序时,系统不会提示我提供任何类型的权限选项。
那么“只有我”是从哪里来的呢?
最佳答案
您不能发布任何超出用户设置权限的内容。因此,您必须将自己帐户的照片权限设置为“必须批准”。查看https://www.facebook.com/help/www/385017548218624查看如何更改您的权限。
关于javascript - 为什么使用 Facebook 的 Graph API(通过 AJAX POST)上传的图片会获得 "Only Me"权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20083523/