Titanium:Facebook API:照片未显示

时间:2015-04-26 21:57:48

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

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

我正在拍照,但它没有显示。如果我使用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]
    });

1 个答案:

答案 0 :(得分:0)

好的,这篇文章持有密钥: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
                                            });