Choose your application, change ‘Response Format’ to JSON, choose method ‘users.hasAppPermission’, fill publish_stream in ext_perm and id of your page in uid.
You should see result: 1.
That means that everything is ok. If the result is 0. then something went wrong. Then check all the above steps again.
Code To Publish on Fan Page as Fan User Using PHP
Then to publish on fan page as a Fan page user and not the facebook user just follow below code.
For this you need to get Fan page ID:
Example : http://www.facebook.com/pages/Fan-Page/xxxxxxx
where xxxxxxx is the fan page id.
In Steam publish method just replace the $page_id with your above fan page id.
There are many Libraries available for C# and Dotnet to publish on facebook.
According to facebook Wiki posting on a wall is very confusing and very difficult to write a program to publish on a wall.
I spent around 2 weeks reading many articles and many documents, Wiki on facebook but in vein and tried many ways and finally I got one workable model. Below are 5 simple steps to publish on a Facebook wall.
Click on “+ Set Up New Application” button to start creating the application as shown below.
Provide the application name, click agree for facebook terms and click on “Create Application” button.
Fill in application Name
Now Application is created for you. Just copy the Application API Key, Application Secret and Application ID details which will be used to write the application code.
Now goto Canvas link and enter any url.
Next goto Connect URL link and enter the same url.
Then click on Save. That’s it we have created a facebook application with an Iframe.
Now Copy Application API Key, Application Secret and Application ID details which will be used to write the application code.
If the user is redirected to the URL specified by the next parameter, then Facebook grants your application a session. This session is appended to the URL as a JSON-decodable object of the form:
If the user grants your application the offline_access extended permission, 0 gets returned for expires and the session never expires unless the user removes the application. In this case, you should store the session key so the user doesn’t have to log in the next time he or she launches your application.
Once the browser has been redirected successfully and you have your session information, you should automatically close the browser window. Note: The above code will execute only once. We should note down the above session key, This will be used to auto login into the application.
If you don’t save these session key values you should generate other token key to create one time session key.
Step4:
Giving Permission to your application to publish on facebook wall. To give permission just replace the your API key in below URL and execute in browser.
If you don’t see the below then your call back URL or Canvas URL must be incorrect, please check again your application settings and execute the URL again.
Then on final page, you will see a success message. That’s it you have given permission for read_stream,publish_stream and offline_access.
Step5: Publishing the message with Image and link on Facebook Wall using cSharp/ C#
Publishing a Post With Image and Action Link in C# using facebook developer toolkit v2
C# Code to create facebook object with onetime session key and publishing the message on Facebook Wall.
public void Post(facebook.API fbAPI, string appLink)
{
string response = fbAPI.stream.publish( "publish steven on facebook.",
new attachment() {
name = "I am a good guy !", href = appLink, caption = "{*actor*} Steven Publish on facebook wall",
description = "Helping other people, I became a new good guy.", properties = null,
media = new List<attachment_media>() { new attachment_media_image()
{ src = "http://blog.theunical.com/wp-content/uploads/2009/11/start-application.jpg", href = appLink } } },
new List<action_link>() { new action_link() { text = "Become a good guy",
href = appLink } }, null, 0);
}
Now you will see the post on wall Great.
So thrilling isn’t we can also publish photos videos on wall.
According to facebook Wiki posting on a wall is very confusing and very difficult to write a program to publish on a wall. And it Don’t even support or document any methods on how to publish on wall using JAVA, and thanks to Google for giving a JAVA library to post on facebook.
I spent around 2 weeks reading many articles and many documents, Wiki on facebook but in vein and tried many ways and finally I got one workable model. Below are simple steps to publish on a Facebook wall using JAVA.
Click on “+ Set Up New Application” button to start creating the application as shown below.
Provide the application name, click agree for facebook terms and click on “Create Application” button.
Fill in application Name
Now Application is created for you. Just copy the Application API Key, Application Secret and Application ID details which will be used to write the application code.
Now goto Canvas link and enter any url.
Next goto Connect URL link and enter the same url.
Then click on Save. That’s it we have created a facebook application with an Iframe.
Now Copy Application API Key, Application Secret and Application ID details which will be used to write the application code.
Note: Please replace “API_KEY” with your application API key from above page.
Then we will get a temporary token key.
This is one time token key that we can use to generate a permanent session key. Careful! Don’t try to execute this programs many times
Step3: Generate one time session key
Below is the sample JAVA code to generate one time session key.
/**
* FacebookClient
*
*/
public class FacebookClient {
public static String API_KEY = “YOUR API KEY”;
public static String SECRET = “YOUR SECRET”;
public static void main(String args[]) {
// Create the client instance
FacebookRestClient client = new FacebookRestClient(API_KEY, SECRET);
client.setIsDesktop(true); // is this a desktop app
try {
String token = client.auth_createToken();
// Build the authentication URL for the user to fill out
String url = “http://www.facebook.com/login.php?api_key=”
+ API_KEY + “&v=1.0″
+ “&auth_token=” + token;
// Open an external browser to login to your application
Runtime.getRuntime().exec(“open ” + url); // OS X only!
// Wait until the login process is completed
System.out.println(“Use browser to login then press return”);
System.in.read();
// fetch session key
String session = client.auth_getSession(token,true );
// obtain temp secret
String tempSecret = client.getSessionSecret();
// new facebook client object
client = new FacebookJaxbRestClient(API_KEY, tempSecret, sessionKey);
System.out.println(“Session key is ” + session);
// keep track of the logged in user id
Long userId = client.users_getLoggedInUser();
System.out.println(“Fetching friends for user ” + userId);
// Get friends list
client.friends_get();
FriendsGetResponse response = (FriendsGetResponse) client.getResponsePOJO();
List<Long> friends = response.getUid();
// Go fetch the information for the user list of user ids
client.users_getInfo(friends, EnumSet.of(ProfileField.NAME));
UsersGetInfoResponse userResponse = (UsersGetInfoResponse) client.getRepsonsePOJO();
// Print out the user information
List<User> users = userResponse.getUser();
for (User user : users) {
System.out.println(user.getName());
}
} catch (FacebookException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
(OR)
For example, the full URL for logging in a user could be:
If the user is redirected to the URL specified by the next parameter, then Facebook grants your application a session. This session is appended to the URL as a JSON-decodable object of the form:
If the user grants your application the offline_access extended permission, 0 gets returned for expires and the session never expires unless the user removes the application. In this case, you should store the session key so the user doesn’t have to log in the next time he or she launches your application.
Once the browser has been redirected successfully and you have your session information, you should automatically close the browser window. Note: The above code will execute only once. We should note down the above session key, This will be used to auto login into the application.
Note: The above code will execute only once. We should note down the above session key, This will be used to auto login into the application.
If you don’t save these session key values you should generate other token key to create one time session key.
We can use the token only once.
Step4: Setting Permission for wall
Giving Permission to your application to publish on facebook wall. To give permission just replace the your API key in below URL and execute in browser.
If you don’t see the below then your call back URL or Canvas URL must be incorrect, please check again your application settings and execute the URL again.
Then on final page, you will see a success message. That’s it you have given permission for read_stream,publish_stream and offline_access.
Step5: Publishing the message on Facebook Wall
Java Code to create facebook object with onetime session key and publishing the message on Facebook Wall.
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpClientParams;
import com.google.code.facebookapi.Attachment;
import com.google.code.facebookapi.AttachmentMediaImage;
import com.google.code.facebookapi.FacebookException;
import com.google.code.facebookapi.FacebookJsonRestClient;
import com.google.code.facebookapi.FeedFacebookPhoto;
import com.google.code.facebookapi.Permission;
import com.google.code.facebookapi.TemplatizedAction;
public class SendtoFacebook {
public static void main (String a[]) throws FacebookException{
SendtoFacebook sfb=new SendtoFacebook();
sfb.send("From My App: publish steven on facebook");
}
public void send(String message)throws FacebookException{
String FB_APP_API_KEY = new String("YOUR_APIKEY");
String FB_APP_SECRET = new String("YOUR_SECRET");
String FB_SESSION_KEY = new String("YOUR_ONETIMESESSIONKEY");
FacebookJsonRestClient facebook = new FacebookJsonRestClient( FB_APP_API_KEY, FB_APP_SECRET, FB_SESSION_KEY );
//FacebookJsonRestClient facebookClient2 = (FacebookJsonRestClient)facebook.getFacebookRestClient();
FacebookJsonRestClient facebookClient = (FacebookJsonRestClient)facebook;
facebookClient.stream_publish(message, null, null, null, null);
System.out.println("successfully updated");
}
}
Now you will see the post on wall Great.
So thrilling isn’t we can also publish photos videos on wall.
Since Facebook has stopped supporting Java we need to use PHP for now to post on a wall.
According to facebook Wiki posting on a wall is very confusing and very difficult to write a program to publish on a wall.
I spent around 2 weeks reading many articles and many documents, Wiki on facebook but in vein and tried many ways and finally I got one workable model. Below are 5 simple steps to publish on a Facebook wall.
Click on “+ Set Up New Application” button to start creating the application as shown below.
Provide the application name, click agree for facebook terms and click on “Create Application” button.
Fill in application Name
Now Application is created for you. Just copy the Application API Key, Application Secret and Application ID details which will be used to write the application code.
Fill the Name and Description of your application in About Link.
Now Click on Website Link to get API Key
Now goto Facebook Integration link and enter any url. Here is where you will get Secret Key.
Enter the Canvas URL and page name. This will be the return URL of your Application.
Facebook Application Facebook Integration
That’s it You now just successfully create a Facebook Application, now lets work on program
Then click on Save. That’s it we have created a facebook application with an Iframe.
Now Copy Application API Key, Application Secret and Application ID details which will be used to write the application code.
Note: Please replace “API_KEY” with your application API key from above page.
Then we will get a temporary token key.
This is one time token key that we can use to generate a permanent session key. Careful! Don’t try to execute this programs many times
Step3: Generate one time session key (permanent session key)
Below is the sample PHP code to generate one time session key.
<?php
// FB_APIKEY is your facebook application api key
// FB_SECRET is your application secrete key
$FB_APIKEY="YOUR_API";
$FB_SECRET="YOUR_SECRET";
$fb = new FacebookRestClient($FB_APIKEY, $FB_SECRET);
$testtoken= "ONETIMETOKEN"; // Replace this value with your Token Value
$result = $fb->call_method('facebook.auth.getSession',
array('auth_token' => $testtoken, 'generate_session_secret' => true));
echo "<br /><pre>";
print_r($result);
echo $session_key = $result['session_key'];
?>
(OR)
For example, the full URL for logging in a user could be:
If the user is redirected to the URL specified by the next parameter, then Facebook grants your application a session. This session is appended to the URL as a JSON-decodable object of the form:
If the user grants your application the offline_access extended permission, 0 gets returned for expires and the session never expires unless the user removes the application. In this case, you should store the session key so the user doesn’t have to log in the next time he or she launches your application.
Note: The above code will execute only once. We should note down the above session key, This will be used to auto login into the application.
If you don’t save these session key values you should generate other token key to create one time session key.
We can use the token only once.
Step4: Setting Permission for wall
Giving Permission to your application to publish on facebook wall. To give permission just replace the your API key in below URL and execute in browser.
If you don’t see the below then your call back URL or Canvas URL must be incorrect, please check again your application settings and execute the URL again.
Then on final page, you will see a success message. That’s it you have given permission for read_stream,publish_stream and offline_access.
Step5: Publishing the message on Facebook Wall
PHP Code to create facebook object with onetime session key and publishing the message on Facebook Wall.
<?php
define('FB_APIKEY', 'YOUR_APIKEY');
define('FB_SECRET', 'YOUR_SECRET');
define('FB_SESSION', 'YOUR_SESSION_key');
require_once('facebook-platform/php/facebook.php');
echo "post on wall";
try {
$facebook = new Facebook(FB_APIKEY, FB_SECRET);
$facebook->api_client->session_key = FB_SESSION;
$fetch = array('friends' =>
array('pattern' => '.*',
'query' => "select uid2 from friend where uid1={$user}"));
echo $facebook->api_client->admin_setAppProperties(array('preload_fql' => json_encode($fetch)));
$message = 'From My App: publish steven on facebook';
if( $facebook->api_client->stream_publish($message))
echo "Added on FB Wall";
} catch(Exception $e) {
echo $e . "<br />";
}
?>
Now you will see the post on wall Great.
So thrilling isn’t we can also publish photos videos on wall.
In my next post see how to publish images and videos to facebook is done