2011-03-30 134 views
4

在朋友的牆上張貼消息,圖API。 我有正在使用該應用程序的用戶的publish_stream擴展權限。使用圖形API在朋友的牆上張貼

如果我想在我的牆上張貼某些東西,代碼就會起作用。

是否有任何方法可以發佈在牆上或發送消息給特定用戶的所有朋友?

請幫忙謝謝!!

以下是代碼,但它不工作。

$friends = $facebook->api('/me/friends'); 
    foreach($friends['data'] as $friend){ 
      $friendsUserId = $friend['id']; 
      echo $friendsUserId . "</br>"; 
      $result = $facebook->api('/$friendsUserId/feed', 'POST', array(    
        message' => 'Test Message'    )); 
      print_r($result); 
     } 

回答

7

這也許是做到這一點。 (未經測試,但我用我的應用程序類似的東西。)

$friends = $facebook->api('/me/friends'); 

    foreach($friends['data'] as $friend) { 
     $facebook->api('/$friend['id']/feed', 'post', array(
        'message' => 'just a test message', 
        'link' => 'http://site.com', 
        'name' => 'just a test name', 
        'caption' => 'just a test caption', 
        'description' => 'just a test description', 
     )); 

} 

這是使用PHP API

+0

這不會工作了。看facebook博客以供參考。 https://developers.facebook.com/blog/post/2012/10/10/growing-quality-apps-with-open-graph/ – Underdog 2013-10-07 10:03:10

3

publish_stream權限只允許您在該特定用戶牆上發佈內容 - 不能張貼在他所有朋友的牆上。

想想這樣 - 說你還沒有授權應用程序在你的臉書牆上發佈任何內容,但僅僅是因爲你的一位朋友允許訪問他的牆 - 它自動不會讓應用程序訪問發佈在他所有朋友的牆。

編輯

拉胡爾,我想昨晚登錄爲自己和通過我的應用程序發佈在我的一個朋友的牆上有一個消息令人驚訝它的工作。我錯誤的印象是你不能那樣做。我很抱歉。

但我仍然無法弄清楚這一點。讓我解釋一下

 
1) I have my real facebook lets call it abc and a test facebook account xyz which I've added as my friend to abc 
2) I login into my app using my abc faceboook account and publish a message on the wall of my friend xyz 
3) Now I login to facebook.com as abc and it shows on my news feed the message that I published on xyz's wall. When I click on xyz's profile - the message shows up on his wall too. So far so good 
4) Now I log out of facebook.com as abc and log back in as xyz. But now I dont see the message that was posted through the app on the wall of xyz. 

我不知道是否有任何延遲,但我已經等了30分鐘,但仍然不存在。但是當我以abc登錄時,它會繼續顯示。

我希望你明白我想在這裏表達。 我用同一塊像您這樣的代碼 - 所以你嘗試了上面的情況,看看是否會遇到類似

感謝

+0

冷靜,但我怎麼公佈的用戶朋友牆?是主要問題。 – 2011-04-01 20:55:55

+0

@rahul - 你不能張貼在用戶朋友的牆上 - 就像我解釋的那樣 - 用戶允許你在他的牆上發佈 - 每個用戶必須給予明確的許可 - 所以它不可能發佈在牆上用戶的朋友 - 這是據我所知 - 我今天會進一步挖掘,看看它是否可能 – Gublooo 2011-04-02 06:02:23

+1

@rahul - 我已經用我昨天做的小測試更新了我的答案。所以我收回我以前的評論,說它不可能。 – Gublooo 2011-04-03 06:30:23

0

Gubloo的答案是接近的東西。

張貼到朋友的牆壁完全是可能的,但有一點需要注意,說的朋友必須通過在某些點上「權限」對話框也不見了。這意味着,您的應用程序的用戶將能夠張貼到您的應用程序的其他用戶的牆上。

我要給你的iPhone的代碼,因爲我不知道PHP和想象你會得到的要點。只需將「我」替換爲您要發佈的任何內容的UID,成爲一個頁面或朋友的個人資料即可。

[_facebook requestWithGraphPath:@"/me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

實際上,我想知道這是否會給予用戶發佈的任何人誰使用的應用程序牆的能力,而不僅僅是他的朋友。

+1

_「說過的朋友在某個時候也必須經歷'權限'對話。」 - - 是什麼給了你這個想法? – CBroe 2012-07-02 17:30:28

+0

我一定是錯的。 – 2012-09-22 18:30:21

5

我只是做了一個小測試,讓用戶的權限,我確實可以通過PHP API發佈用戶的朋友的牆上寫着:

$facebook->api('/[FRIEND_ID]/feed', 'post', array(
      'message' => 'test message', 
      'link' => 'http://google.com', 
      'name' => 'test name', 
      'caption' => 'test caption', 
      'description' => 'test long description', 
    )); 
0

$ friends = $ facebook-> api('/ me/friends');

foreach($friends['data'] as $friend) { 
    $facebook->api('/$friend['id']/feed', 'post', array(
       'message' => 'just a test message', 
       'link' => 'sample link.com', 
       'name' => 'just a test name', 
       'caption' => 'just a test caption', 
       'description' => 'just a test description', 
    )); 

} 以上爲我工作代碼tooooo 謝謝你的職位

相關問題