将事件配置文件图片发布到页面javascript sdk时出现问题

时间:2012-06-20 15:28:40

标签: javascript facebook facebook-graph-api

好的,我正在使用javascript API处理Facebook Graph API。我一直在努力在用户页面上创建事件,而不是他们的个人资料,我的工作正常。但是,当我尝试使用事件上传个人资料图片时,该事件会成功创建,但没有图片。

我尝试了很多解决方案,但尚未找到有效的解决方案。

以下是我目前的情况:

 function SubmitEvent(descrip, name, start,end, line1, city, state, zip, lat, lon,path)

    {
           var eventMsg = document.getElementById('event-msg');

            var myJsonEvent = {
                "name": name,
                "description": descrip,
                "start_time": start,
                "end_time": end,
                "location": city + ", " + state,
                "venue": {
                    "street": line1,
                    "city": city,
                    "state": state,
                    "country": "United States",
                    "latitude": lat,
                    "longitude": lon
                },
                "privacy": "OPEN",
                "picture": 
            "http://stage.localruckus.com/Content/Uploads/Thumbnails/Eddie%20Delahunt_card_
                          84dc116b-f7e5-477b-b0bb-60ecdbe41955.jpg"

            };

            var select = document.getElementById("facebook-page-select");
            var pageId = select.options[select.selectedIndex].value;
            var res;
            FB.api(pageId, 'post', myJsonEvent, function (result) {
                console.log(result);
                if (result.id == undefined) {
                    eventMsg.innerHTML = 'There was a problem creating the event, please 
                          try  again. Error: '+result.message;
                }
                res = result.id;
                eventMsg.innerHTML = 'Event posted id: ' + result.id;
                eventId = result.id;
                postPicture(path);

            });


    }

    function postPicture(path) {
        var cookie = eventId;
        var token = getCookie('access');
        if (cookie != null && cookie != undefined && token != null && token != undefined) {
           $.ajax({
                type: "POST",
                url: "https://graph.facebook.com/" + cookie,
                data: {
                    message: "Event picture",
                    url:
            "http://stage.localruckus.com/Content/Uploads/Thumbnails/Eddie%20Delahunt_card_
                         84dc116b-f7e5-477b-b0bb-60ecdbe41955.jpg",
                    access_token: token,
                    format: "json"
                },
                success: function (data) {
                    alert("Picture posted successfully");
                } 
        });

     }
    }

postPicture方法或使用事件创建api调用提供图像路径似乎都不起作用,虽然我没有得到任何错误或类似的东西。

我花了很多时间在google,SO和facebook文档上,但尚未找到答案。我在facebook docs中找到了这个小片段:


图片

向/ EVENT_ID / picture发出HTTP GET请求会返回HTTP 302重定向到事件配置文件图片的URL。

创建/更新

您可以通过向/ EVENT_ID / picture发出HTTP POST请求,为事件管理员和以下参数发出create_event权限,从而向事件添加个人资料图片:

参数描述类型必需

源图片内容multipart / form-data yes

如果请求成功,则返回true。

删除

您可以通过向事件管理员发出带有create_event权限的?EVENT_ID /图片的HTTP DELETE请求来删除事件的个人资料图片。

如果请求成功,则返回true。


但是我还没有找到神秘的“源”参数,或者当数据不来自表单时如何创建/发布多部分表单数据。

有人可以帮帮我吗?我非常感谢你能给我的任何帮助。

1 个答案:

答案 0 :(得分:2)

BUG:目前有2个与此问题相关的错误。

https://developers.facebook.com/bugs/459815400713534

https://developers.facebook.com/bugs/339792622758072


你试过url编码图片的链接吗?我相信当它从表单发布时,表单会对网址进行编码。由于您没有使用表单发布,因此您必须自己编码。

picurl = encodeURIComponent('http://stage.localruckus.com/Content/Uploads/Thumbnails/Eddie%20Delahunt_card_
                         84dc116b-f7e5-477b-b0bb-60ecdbe41955.jpg');

在这里测试http://jsfiddle.net/ShawnsSpace/e7E4c/