views:

2845

answers:

7

Ok So I haven't tried messing with the facebook PHP API for months.. it's gross. Since template bundles are apparently now defunct, how can I publish a story into my users news feed for their friends? I've also already requested permissions. Edit: The issue seems to arise from requested permissions not being set for the user when They are granted.

So far I have this

$appapikey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$appsecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$facebook = new Facebook($appapikey, $appsecret);
$fb_user = $facebook->require_login();

try {
    $facebook->api_client->feed_publishUserAction();
} catch(Exception $e) { }

edit: I've looked through the facebook "api documentation" multiple times it's just not clear to me. I can't tell what's actually deprecated or not. They link to tutorials 2-3 years old!

if you have a problem with your iframe application reloading over and over and over try using

$facebook->require_frame()

+1  A: 

Have you already looked up the topic on the facebook wiki? http://wiki.developers.facebook.com/index.php/Stream.publish

There's a nice example which should help you out. If not, you'll have to describe your problem more accurate.

EDIT: You can check and request for the permissions like this (and also request them)

function check_perms() {

    global $facebook, $uid;

    $data = $facebook->api_client->fql_query( "SELECT uid, publish_stream FROM permissions WHERE uid = " . $uid );
    if( $data[0]['publish_stream'] != true ) {
        echo '<br /><p>No \'publish_stream\' permissons found!<br />';
        echo '<fb:prompt-permission perms="publish_stream"> Allow me to publish to your wall (*click*) </fb:prompt-permission>';
        echo '<br />You\'ll have to refresh the page to continue.</p>';
        die();
    }

}
svens
With your suggestion I tried simply using the example they provided. and attempted to pass it with my application on a form submit and it just died because I dont have the right permissions from the user(myself) If you could tell me what permissions to request when a user first uses my app? link to my app is http://apps.facebook.com/mynamemeanswhat
AFK
After requesting stream_publish for myself using my app, I checked what permissions I had with the app, and it is only for one line stories.. how do I request permissions for the multi-line stories like provided in the examples?
AFK
I've updated my answer :)
svens
Ok, so I tried it. and it tells me I don't have the publish_stream permission. I've used the fbml to ask for it whenever the application is first visited, and the dialog shows up and I click accept. but now after it is installed it does not show the dialog. It only shows the text "Allow me to publish to your wall (*click*) " and nothing else. So the problem seems not to be streamPublish command but the ability to get the permission from the user. It's just not sticking.
AFK
http://stackoverflow.com/questions/1426681/how-to-make-a-pop-up-to-ask-user-for-extended-permission-in-an-i-frame-applicatio modified the answer here to redirect to get permissions for my app using your code for when the user doesnt have permissions. The FBML doesn't work for my Iframe app :] SUCCESS
AFK
Glad to hear that. And btw yes, the documentation is not always very helpful ;).
svens
+1  A: 
    <?php
          $message ="Your Message";
           $attachment = array( 
            'name' => 'Application Name or message', 
            'href' => 'http://apps.facebook.com/tshirtquote', 
            'description' => 'Choose/Write your T-shirt Quote, Get A Tshirt Free printed with your Favorite Quote',
            'media' => array(array('type' => 'image', 'src' => 'http://linkdoo.com/tshirtquote/images/tshirt1.JPG', 'href' => 'http://apps.facebook.com/tshirtquote/')), 
            ); 
           $action_links = array( array('text' => 'WriteYourTShirtQuote', 'href' =>   'http://apps.facebook.com/tshirtquote')); 
           $attachment = json_encode($attachment); 
           $action_links = json_encode($action_links);
           $message = json_encode($message);
      ?>
     <script>
     var attachment = <?= $attachment ?>;
     var message = <?= $message ?>;
     var action_links = <?= $action_links ?>;
     Facebook.streamPublish(message,attachment,action_links);

     </script>

Use above script , It is most easy way to publish

vinayrks
What is the script? Is it Javascript? It worked when it was a file by itself, but when I added it to my actual PHP file... it fails without error.
Zachary Brown
A: 

Hey jan that works great for me, my knowlage is exceptionally limited when it comes to php and javascript. Could you possible tell me how i would trigger the code you posted onClick?

salmon
Sorry for asking so many questions haha i have the above sorted, turned out to be pretty easy =] Would it be possible to post the content to the news feed without opening up the box or asking the user to publish?
salmon
Yea, you can just ask for stream_publish though how varies widely.. then you can post whatever without alerting the user at all.
AFK
A: 

Is there any way to customized the stream publish popup window ?

suzan
A: 

hello, sorry bro, did not work for me....It did not publish anything on my facebook wall.. please email me the complete code at [email protected]. please buddy I am in Problem. need to resolve this soon. Please. I am working in PHP environment.

Regards

Rahul Anand 08146759754

Rahul
I don't think it's wise to post your email address and presumebly, telephone number.
Martin Bean
A: 

Rahul,

Have you gotten a code that can post to a friend's wall with a popup window?