Facebook API适用于/ feed,但不适用于/照片

编程入门 行业动态 更新时间:2024-10-23 02:51:40
本文介绍了Facebook API适用于/ feed,但不适用于/照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

以下代码如果我通过 / pageid / feed 到 facebook-> api ,但是当我更改它将图像直接上传到我的Facebook相册时,它将无法正常工作。请在以下代码中告诉我我做错了什么:

Following is the code that works fine if I am passing /pageid/feed to facebook->api, but when I change it to upload the image directly to my Facebook photo album, it will not work. Kindly let me know what I am doing wrong in the following code:

// Works fine $status = $facebook->api("/194458563914948/feed", 'post', $attachment); // Does not work $status = $facebook->api("/196878530339618/photos", 'post', $attachment);

完整来源

Full Source

<?php require 'src/facebook.php'; $app_id = "332267477347"; $app_secret = "xxxx"; $facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, 'cookie' => true, 'fileUpload' => true, )); $facebook->setFileUploadSupport(true); $user = $facebook->getUser(); //echo $user; if(($facebook->getUser())==0) { header("Location:{$facebook->getLoginUrl(array('scope' => 'photo_upload,user_status,publish_stream,user_photos,manage_pages'))}"); exit; } else { $accounts_list = $facebook->api('/me/accounts'); echo "i am connected"; } $valid_files = array('image/jpeg', 'image/png', 'image/gif'); //to get the page access token to post as a page foreach($accounts_list['data'] as $account){ if($account['id'] == 194458563914948){ // my page id =123456789 $access_token = $account['access_token']; echo "<p>Page -- Access Token: $access_token</p>"; } } //posting to the page wall if (isset($_FILES) && !empty($_FILES)) { $aid = '421539304540205'; $folder = "pak/".$_FILES['pic']['name']; $fold = 'snowdrop.pk/fb/'.$folder; echo $fold."<br>"; if( move_uploaded_file($_FILES['pic']['tmp_name'], $folder) ) { #Upload photo here $img = realpath($_FILES["pic"]["tmp_name"]); $attachment = array('message' => $_POST['textfield'], 'aid' => $aid, 'source' => '@' . $img, 'access_token' => $access_token, ); $status = $facebook->api("/421539304540205/photos", 'post', $attachment); echo $status; var_dump($status); } else{ echo 'Only jpg, png and gif image types are supported!'; } } ?> <body> <!-- Form for uploading the photo --> <div class="main"> <p>Select a photo to upload on Facebook Fan Page</p> <form method="post" action="" enctype="multipart/form-data"> <p>Select the image: <input type="file" name="pic" /> <br /> <label>Description <input type="text" name="textfield" id="textfield" /> </label> </p> <p><input class="post_but" type="submit" value="Upload to my album" /></p> </form> </div> </body>

推荐答案

您正在使用的路径 / 406221796071956 /照片是错误的,这就是为什么它不起作用。

The path you are using /406221796071956/photos is wrong and that's why it does not work.

这个路径错误的原因是,406221796071956 是id的照片,请自行查看 Graph API Explorer for 406221796071956 说:

The reason that this path is wrong, is that 406221796071956 is the id of a picture, see for yourself, the Graph API Explorer for 406221796071956 says:

type:photo

"type": "photo"

如果要发布到该专辑,那么使用 / 196878530339618 / photos ,因为它是专辑:

If you want to publish to that album then use /196878530339618/photos, since it's the album: Graph API Explorer for 196878530339618

type:album

"type": "album"

编辑

请参阅 developers.facebook/docs/reference/api/album/#photos 将照片添加到

根据相册对象:

can_upload

确定UID是否可以上传到相册,如果用户拥有专辑,相册不满,该应用可以添加照片到相册

Determines whether the UID can upload to the album and returns true if the user owns the album, the album is not full, and the app can add photos to the album

所以你需要相册充满,成为专辑的所有者,并拥有正确的上传权限。

So you need the album not to be full, to be the owner of the album and have the right permissions for uploading.

更多推荐

Facebook API适用于/ feed,但不适用于/照片

本文发布于:2023-11-23 14:06:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621711.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适用于   但不   照片   Facebook   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!