【发布时间】:2015-01-20 05:57:19
【问题描述】:
如何在 Titanium 的 Facebook 模块对话框中添加图片?在 Titanium 的示例中,对话框中的图片属性是来自网站的图片链接:
var data =
{
link : "http://www.appcelerator.com",
name : "Appcelerator Titanium Mobile",
message : "Checkout this cool open source project for creating mobile apps",
caption : "Appcelerator Titanium Mobile",
picture : "http://developer.appcelerator.com/assets/img/DEV_titmobile_image.png",
description : "You've got the ideas, now you've got the power. Titanium translates " +
"your hard won web skills into native applications..."
};
fb.dialog("feed", data, function(e)
{
if(e.success && e.result)
{
alert("Success! New Post ID: " + e.result);
}
else
{
if(e.error)
{
alert(e.error);
}
else
{
alert("User canceled dialog.");
}
}
});
但是,如果您想使用本地图片而不是通过此类网站的链接,该怎么办?
var data =
{
link: "http://play.google.com/",
name: "Android app's name",
picture: "file:///data/data/com.appid/app_appdata/directory/name-of-image.jpg"
};
如果我使用上面的代码,我会收到图片属性格式错误。请参阅此图片以获取视觉参考:http://postimg.org/image/wjefdlalb/
我尝试过像这样使用文件系统:
function getFile()
{
var imageFileToPost;
var imageFile = Ti.Filesystem.getFile("file:///data/data/com.appid/app_appdata/directory/name-of-image.jpg");
if (imageFile.exists())
{
console.log("exists");
imageFileToPost = imageFile.read();
}
return imageFileToPost;
}
var data =
{
link: "http://play.google.com/",
name: "Android app's name",
picture: getFile()
};
并且发布成功,没有错误,但是图片没有在 Facebook 上发布。
注意:我会使用图表,但我需要使用“publish_actions”之类的权限,这意味着我必须让 Facebook 审核应用程序,但他们不喜欢预填充消息,即使用户无论如何都可以编辑消息。那么这真的只是 Facebook 模块对话框的格式问题,还是只需要图片的 URL?如果是格式问题,谁能告诉我如何正确格式化,因为我真的需要使用本地图片而不是来自网站的图片?
【问题讨论】:
-
你可能想检查this post
-
嗨 Turtle,感谢您抽出宝贵时间,但我不想使用 Graph。我使用了图表并使用了 publish_actions,但被 Facebook 拒绝了,因为我有用户可以编辑的预填充消息。 Facebook 只是不喜欢预填充消息 a 和对话框让我可以拥有链接和图片等预填充数据,而无需询问 Facebook 的权限。
标签: android facebook image formatting titanium