views:

105

answers:

1

Hello everyone, i have been going crazy and cant figure out how to make a script for my application that would allow the user to select a friend and send them a notification or post on their wall from my application.

I just need to notify their friend that they have been challenged to play a flash games, just a simple text with a link, i dont need anything fancy :D

Here is what i tried and it doesnt work :( no idea why.

$message = 'Watch this video!';
 $attachment = array( 'name' => 'ninja cat', 'href' => 'http://www.youtube.com/watch?v=muLIPWjks_M', 'caption' => '{*actor*} uploaded a video to www.youtube.com', 'description' => 'a sneaky cat', 'properties' => array('category' => array( 'text' => 'pets', 'href' => 'http://www.youtube.com/browse?s=mp&t=t&c=15'), 'ratings' => '5 stars'), 'media' => array(array('type' => 'flash', 'swfsrc' => 'http://www.youtube.com/v/fzzjgBAaWZw&hl=en&fs=1', 'imgsrc' => 'http://img.youtube.com/vi/muLIPWjks_M/default.jpg?h=100&w=200&sigh=__wsYqEz4uZUOvBIb8g-wljxpfc3Q=', 'width' => '100', 'height' => '80', 'expanded_width' => '160', 'expanded_height' => '120')));
 $action_links = array( array('text' => 'Upload a video', 'href' => 'http://www.youtube.com/my_videos_upload'));
 $target_id = $user;
 $facebook->api_client->stream_publish($message, $attachment, $action_links, $target_id);

UPDATE: appinclude.php

$facebook->redirect('https://graph.facebook.com/oauth/authorize?client_id=132611566776827&redirect_uri=https://apps.facebook.com/gamesorbiter/&scope=publish_stream');

Error i get:

{
   "error": {
      "type": "OAuthException",
      "message": "Invalid redirect_uri: The Facebook Connect cross-domain receiver URL (https://apps.facebook.com/gamesorbiter/) must be in the same domain or be in a subdomain of an application's base domain (gamesorbiter.com).  You can configure the base domain in the application's settings."
   }
}

Without the extra "s"(http) i get this error:

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

Please if you could post an example. Also do i need extended permission to do that or if the user sends the message i dont need that ?

Thank You

A: 

Also do i need extended permission to do that or if the user sends the message i dont that ?

Yes, you need the offline_access and publish_stream extended permission from the users.

Update:

In your appinclude.php file, put code like this:

$facebook = new Facebook($appapikey, $appsecret);
$user = $facebook->require_login();

$facebook->redirect('https://graph.facebook.com/oauth/authorize?
client_id=[YOUR APP ID]&
redirect_uri=[YOUR APP URL]&
scope=publish_stream, offline_access');

Replace [YOUR APP ID] with application id that you can see from application settings where you created the site in Facebook Developers section. Also replace the [YOUR APP URL] with your app url.

Sarfraz
I have this code in my appinclude.php[code]$facebook = new Facebook($appapikey, $appsecret);$user = $facebook->require_login($required_permissions = 'publish_stream');[/code]But when i remove the application from my profile and access it again i get the same old basic permission dialog. Why isnt the app asking for publish_stream permission ?
Krasi
@Krasi: See this to get any permissions you want: http://developers.facebook.com/docs/authentication/
Sarfraz
Oh, i applied for an extended permission for my application and hopefully facebook will approve my application.There is no way for me to let the user send a message to another user through my app and basically go around the permission issue ?
Krasi
@Krasi: see my updated answer please.
Sarfraz
I tried that and after accepting the permissions i get Invalid session key.Why is that ?
Krasi
@Krasi: What is your application id?
Sarfraz
I think its because they havent authorized my application to request that kind of permission yet but when i try it on my admin account i get an infinite loop. My application id is: 132611566776827
Krasi
You need to put your app id eg `132611566776827` in the redirect function i posted where it says `client_id`
Sarfraz
Oh, i thought it was the api key i had to put i there. I put the app id this time and got this error: Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
Krasi
@Krasi: make sure that you have `openssl` extension turned on from php.ini. Also post your code after you have modified it after my suggestion.
Sarfraz
Here is the modified code, and i am not sure how to turn on openssl:<code>$facebook = new Facebook($appapikey, $appsecret);$user = $facebook->require_login();$facebook->redirect('https://graph.facebook.com/oauth/authorize?client_id=132611566776827</code>
Krasi
You are missing `https://` part in the url in the `redirect` function.
Sarfraz
Error, do i have to change the app base url ?Invalid redirect_uri: The Facebook Connect cross-domain receiver URL (https://apps.facebook.com/gamesorbiter/) must be in the same domain or be in a subdomain of an application's base domain (gamesorbiter.com). You can configure the base domain in the application's settings.
Krasi
In the redirect url try specifying both apps.facebook.com/gamesorbiter or your actual server url that you have specified in the application settings.
Sarfraz
I tried the actual sever url but i get 404 error.If i try to access my website using https the server cant find any documents. weird.
Krasi
@Krasi: I had told you to post your modified code in your question not here. Also that `openssl` extension is turned on from php.ini.
Sarfraz
<code>$facebook->redirect('https://graph.facebook.com/oauth/authorize?client_id=132611566776827</code>I think openssl in enabled, this is what i have the php.ini : extension=php_openssl.dll , btw how do you post code without pressing the code button ?
Krasi
@Krasi: You have placed your code here again :( **Please put your modified code by editing your OWN question above**
Sarfraz
oh ok :) sorry. done
Krasi
@Krasi: You are putting an extra `s` in your redirect url `https://apps.facebook.com/gamesorbiter/`. Remove `s` from `https` and use `http:`
Sarfraz
without the extra s i get infinite redirect, like i said before.
Krasi
@Krasi: Ok then put your server path in redirect url like `http://www.mysite.com/mapp/index.php` Specify the path that you have put in the convas application settings.
Sarfraz
I tried that, when i do that the page keeps refreshing forever. no error but it refreshes forever.
Krasi
got to go, talk to you tomorrow :DThanks for the help.
Krasi
@Krasi: Ok no problem....
Sarfraz