1

我想在移动设备上使用以下代码将 base64 图像分享到 facebook。一些浏览器可以工作(Chrome、Firefox 等),但 android 浏览器不工作。

它只显示

"*{"error":{"message":"(#324) Requires upload file","type":"OAuthException","code":324}}"*

我已经花了三天,但我无法解决它,我不知道这段代码有什么问题。有人可以帮忙吗??

function sharephoto(){
    var imageData = "....";//base64 data mage
    var mimeType = "image/jpeg";
    try{
        var blob = dataURItoBlob(imageData,mimeType);
    }catch(e){
        console.log(e);
    }
    var fd = new FormData();
    fd.append("access_token",accessToken);
    fd.append("source", blob);
    fd.append("message","image message");

    var xhr=new XMLHttpRequest();
    xhr.open( 'POST', 'https://graph.facebook.com/'+ uid + '/photos?access_token=' +         accessToken, true );
    xhr.onload = xhr.onerror = function() {
        console.log( xhr.responseText );
    };
    xhr.send(fd);           
}

function dataURItoBlob(dataURI,mime) {
    var byteString = window.atob(dataURI);
    var ia = new Uint8Array(byteString.length);

    for (var i = 0; i < byteString.length; i++) {
        ia[i] = byteString.charCodeAt(i);
    }
    try {
        return new Blob([ia], {type: mime});
    } catch (e) {
        var BlobBuilder = window.WebKitBlobBuilder || window.MozBlobBuilder;
        var bb = new BlobBuilder();
        bb.append(ia);
        return bb.getBlob(mime);
    }               
}
4

0 回答 0