【问题标题】:Can I set the user's photo to Titanium ACS?我可以将用户的照片设置为 Titanium ACS 吗?
【发布时间】:2014-01-09 11:46:48
【问题描述】:

我需要向我的用户添加一张照片,通过从 Web 界面执行此操作,我将照片设置为一个名为 photo 的字段,但如果我尝试从移动应用程序以编程方式执行相同的操作,它不会不行。

photonativePath 是我在相机或图库中的照片网址。

Cloud.Users.update({
    email: 'joeuser@mycompany.com',
    first_name: 'joe',
    last_name: 'user',
    photo : Titanium.Filesystem.getFile(photonativePath),
    custom_fields: {
        favorite_color: 'blue',
        age: 25
    }
}, function (e) {
    if (e.success) {
        var user = e.users[0];
        alert('Success:\n' +
            'id: ' + user.id + '\n' +
            'first name: ' + user.first_name + '\n' +
            'last name: ' + user.last_name);
    } else {
        alert('Error:\n' +
            ((e.error && e.message) || JSON.stringify(e)));
    }
});

【问题讨论】:

  • 你遇到了什么错误?
  • 还有photonativePath的值是什么
  • photonativePath 是我来自相机或画廊的照片网址。

标签: titanium appcelerator titanium-mobile acs


【解决方案1】:

试试下面的, 您可以使用 openPhotoGallery 方法打开照片库。这将从图库中打开图像并选择图片。成功回调中会更新图片

function openPhotoGallery(){
    Ti.Media.openPhotoGallery({
        success: function (event){
            var image=event.media;
            var imgvwTest = Ti.UI.createImageView({
                image : image
            });
            updatePhoto(imgvwTest.toImage());
        },
        cancel:function(){
            Titanium.UI.createAlertDialog({
                title:'Error', 
                message:'An error occured while trying to reference your gallery!'
            }).show();
        },
        error:function(er){
            Titanium.UI.createAlertDialog({
                title:'Error', 
                message:'An error occured while trying to reference your gallery!'
            }).show();
        }
    });

}

function updatePhoto(selectedImage){

    Cloud.Users.update({
        email: 'joeuser@mycompany.com',
        first_name: 'joe',
        last_name: 'user',
        photo : selectedImage.media,
        custom_fields: {
            favorite_color: 'blue',
            age: 25
        }
    }, function (e) {
        if (e.success) {
            var user = e.users[0];
            alert('Success:\n' +
                'id: ' + user.id + '\n' +
                'first name: ' + user.first_name + '\n' +
                'last name: ' + user.last_name);
        } else {
            alert('Error:\n' +
                ((e.error && e.message) || JSON.stringify(e)));
        }
    });
}

如果您有任何问题,请告诉我

【讨论】:

  • 不行,我成功了但是照片还没设置好
  • 您在 ACS 服务器中查看过照片吗?那里有吗?
  • 好的,同样的代码对我有用!!!您可以尝试在 updatePhoto 方法中使用 selectedImage.media 代替 selectedImage 吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-18
  • 2015-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多