Facebook C#SDK和Web API - (OAuthException - #120)(#120)无效的专辑ID

时间:2015-01-25 20:24:35

标签: facebook facebook-graph-api asp.net-web-api

我有一个客户端应用程序,可以对Facebook进行身份验证,然后将访问令牌提供给使用Facebook C#SDK的Web API方法,例如发布到用户的相册:

var facebook = new FacebookClient(photoDTO.FacebookSessionToken);

dynamic result = facebook.Post("me/photos",
                    new
                    {
                        message = photoDTO.Photo.Comments,
                        file = new FacebookMediaObject
                        {
                            ContentType = "image/jpeg",
                            FileName = fileName,
                        }.SetValue(imageBytes)
                    });

此代码过去有效,但现在我得到一个例外:"(OAuthException - #120)(#120)无效的专辑ID"。我认为此错误与身份验证令牌有关,但我已通过浏览https://graph.facebook.com/me?access_token=检查该令牌是否有效...并且它确实正确返回当前登录的用户的配置文件该应用程序。我使用的是SDK版本6.0.10.0。

如何使用从客户端应用程序传递的身份验证令牌发布到当前登录用户的配置文件?

2 个答案:

答案 0 :(得分:0)

不确定这是一个答案还是仅仅是一种解决方法,但由于我知道我想要发布的相册的名称,我查询了用户的相册以获取相册ID,然后使用该相册直接发布到专辑:

var facebook = new FacebookClient(photoDTO.FacebookSessionToken);

string albumId = null;
string albumName = "Album";
dynamic albums = facebook.Get("me/albums");

// Get the album id of the album we want to post to
foreach(dynamic albumInfo in albums.data)
{
    if (albumInfo.name == albumName)
    {
        albumId = albumInfo.id;
        break;
    }
}

// If album does not exist, create it
if (albumId == null)
{
    dynamic album = facebook.Post("me/albums",
                        new
                        {
                            name = albumName
                        });

    albumId = album.id;
}

// Post the photo to the album                
dynamic photo = facebook.Post("/" + albumId + "/photos",
                    new
                    {
                        message = photoDTO.Photo.Comments,
                        file = new FacebookMediaObject
                        {
                            ContentType = "image/jpeg",
                            FileName = fileName,
                        }.SetValue(imageBytes)
                    });

答案 1 :(得分:0)

请注意,相册ID与相册名称不同,这是您将相册ID与相册名称进行比较的问题!检查相册api here

正确的算法是:

查找相册ID,如果有,则将媒体发布到指定ID,否则处理错误

FB.api(
    "/{album-id}",
    function (response) {
      if (response && !response.error) {
        //album was found , your code goes right here.
      }
     else {
        //album was not found handle your error.
      }

    }
);