【问题标题】:Titanium: Facebook API: Photo not showingTitanium:Facebook API:照片未显示
【发布时间】:2015-04-26 21:57:47
【问题描述】:

这里开始扯头发了,没有东西可以尝试了。

我正在拍照,但它没有显示。如果我使用 URL,那么它可以工作。 我正在使用 API 示例,所以不确定我做错了什么? 我在 Facebook 页面上看到的唯一内容是消息,而不是照片。

photoButton.addEventListener('click',function(e){

    var image = e.media;
    var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'camera_photo.png');
    f.write(image);
    var blob = f.read();

    Titanium.Media.showCamera({
        success:function(event) {
            Ti.API.debug('Our type was: '+event.mediaType);
            if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {

                // send XHR req to post image on Facebook

                fb.permissions = ['publish_actions', 'status_update', 'publish_stream', 'read_stream','manage_pages']; // Permissions your app needs
                fb.authorize();


                var data = {
                    name : "This is my name",
                    message : 'This is my message',
                    caption : "This is the caption",
                    picture : blob
                };

                fb.requestWithGraphPath('1234567890/feed', data, 'POST', function(e) {
                    if (e.success) {
                        alert(e.result);
                    } else if (e.error) {
                        alert(e.error);
                    } else {
                        alert('Unknown response');
                    }
                });


            } else {
                alert("got the wrong type back ="+event.mediaType);
            }
        },
        cancel:function() {
     // called when user cancels taking a picture
        },
        error:function(error) {
     // called when there's an error
            var a = Titanium.UI.createAlertDialog({title:'Camera'});
     if (error.code == Titanium.Media.NO_CAMERA) {
                a.setMessage('Овој уред нема камера');
            } else {
                a.setMessage('Unexpected error: ' + error.code);
            }
            a.show();
        },
        saveToPhotoGallery:true,
     // allowEditing and mediaTypes are iOS-only settings
        allowEditing:true,
        mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
    });

【问题讨论】:

  • 为什么不直接将文件路径传递给 API 呢? var str = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'camera_photo.png').read();picture : strvar data
  • 我刚做了,没有运气?
  • 您应该使用 {page_id}/photos 端点来上传照片。见developers.facebook.com/docs/graph-api/reference/page/…

标签: facebook facebook-graph-api titanium titanium-mobile


【解决方案1】:

好的,这个帖子掌握关键:Appcelerator Titanium: Facebook Image Upload fail

问题是由于某种原因提要无法与 FB 模块一起使用,因此您必须使用 XHR 请求:

var endPoint = 'https://graph.facebook.com/v2.1/' + pid + '/photos?access_token='+ acc;
                                            xhr.open('POST',endPoint);
                                            xhr.send({
                                                message: data,
                                                picture: image
                                            });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多