Monday, April 11, 2011

How to post from facebook app to facebook page?

* NOTE :-

Please follow all the steps carefully and sequentially. Users are advised to follow every step in different tab.


For all the steps we are considering following options :-

1. FB Page :-
Name : Sample Page
{PAGE_ID} : 121364427524405

2. FB App :-
Name : Sample App
{APP_ID} : 303409109772222
{API_KEY} : 222223632fdc6ffffe4a53a453333333
{APP_SECRET} : 1111111111111115f3939c1513ee0844

3. {REDIRECT_URL} :- http:/myexample.com/one.php



In order to post data from App page to other page we have to follow the following steps:-


1.)
synopsis : https://www.facebook.com/dialog/oauth?client_id={APP_ID}&redirect_uri={REDIRECT_URL}&scope=email,read_stream,offline_access,manage_pages


e.g.

https://www.facebook.com/dialog/oauth?client_id=303409109772222&redirect_uri=http://myexample.com/one.php&scope=email,read_stream,offline_access,manage_pages

Redirected to :-
http://myexample.com/one.php?code=60ad2f9f47cdaf5e03176824-100000098944650|W8_4DqYq_KCX_oBaa11oJJQ373Q

Output on redirect URL's screen :
[access_token] =} 303409109772222|60ad2f9f47cdaf5e03176824-100000098944650|xAOzhvZAJELuLgJVouW1l7nrMLQ

2.)
synopsis : https://graph.facebook.com/oauth/access_token?client_id={APP_ID}&redirect_uri={REDIRECT_URL}&client_secret={APP_SECRET}&code={CODE_GENERATED_IN_REDIRECT_TO_URL_IN_STEP_1}


e.g.

https://graph.facebook.com/oauth/access_token?client_id=303409109772222&redirect_uri=http://myexample.com/one.php&client_secret=1111111111111115f3939c1513ee0844&code=60ad2f9f47cdaf5e03176824-100000098944650|W8_4DqYq_KCX_oBaa11oJJQ373Q


Output on redirect URL's screen :
[access_token] =} 303409109772222|60ad2f9f47cdaf5e03176824-100000098944650|xAOzhvZAJELuLgJVouW1l7nrMLQ


3.)
synopsis : https://www.facebook.com/dialog/oauth?client_id={APP_ID}&redirect_uri={REDIRECT_URL}&scope=email,read_stream&response_type=token

e.g.

https://www.facebook.com/dialog/oauth?client_id=303409109772222&redirect_uri=http://myexample.com/one.php&scope=email,read_stream&response_type=token


4.)
synopsis : https://graph.facebook.com/oauth/access_token?client_id={APP_ID}&client_secret={APP_SECRET}&grant_type=client_credentials

e.g.

https://graph.facebook.com/oauth/access_token?client_id=303409109772222&client_secret=1111111111111115f3939c1513ee0844&grant_type=client_credentials

Output on redirect URL's screen :
access_token=303409109772222|ifLwz-k7HwQvG5MfOeg3Y_6fGsQ



5.)
synopsis : https://www.facebook.com/dialog/oauth?client_id={APP_ID}&redirect_uri={REDIRECT_URL}&scope=manage_pages&response_type=token

e.g.

https://www.facebook.com/dialog/oauth?client_id=303409109772222&redirect_uri=http://myexample.com/one.php&scope=manage_pages&response_type=token


6.)
synposis : https://graph.facebook.com/me/accounts?access_token={ACCESS_TOKEN_GENERATED_FROM_STEP_1}

* NOTE : This URL will yield the listing of all pages in JSON format. We will have to find out the ACCESS_TOKEN of that page, on which we have to post.

e.g.

https://graph.facebook.com/me/accounts?access_token=303409109772222|60ad2f9f47cdaf5e03176824-100000098944650|xAOzhvZAJELuLgJVouW1l7nrMLQ


Output on redirect URL's screen :

{"data":[{"name":"Sample Page","category":"Media\/news\/publishing","id":"121364427524405","access_token":"303409109772222|60ad2f9f47cdaf5e03176824-100000098944650|121364427524405|LDf-47eJi-dYgjourPlz4Kp78Jg"}]}


In our case we have to post on Sample page - the first entry in our JSON string. So we will extract access_token parameter of this JSON string for future usage.



7.)
synposis : http://www.facebook.com/login.php?api_key={API_KEY}&connect_display=popup&v=1.0&next={REDIRECT_URL}&cancel_url=http://www.facebook.com/connect/login_failure.html&fbconnect=true&return_session=true&session_key_only=true&req_perms=read_stream,publish_stream,offline_access

e.g.

http://www.facebook.com/login.php?api_key=222223632fdc6ffffe4a53a453333333&connect_display=popup&v=1.0&next=http://myexample.com/one.php&cancel_url=http://www.facebook.com/connect/login_failure.html&fbconnect=true&return_session=true&session_key_only=true&req_perms=read_stream,publish_stream,offline_access

Redirected to :-
http://myexample.com/one.php?session={%22session_key%22%3A%2260ad2f9f47cdaf5e03176824-100000098944650%22%2C%22uid%22%3A100000098944650%2C%22expires%22%3A0%2C%22secret%22%3A%227367a1a32dc7240e8b2fd50c48331c8a%22%2C%22sig%22%3A%22fcf7ce7683a13ffb83a4d96a2aa7f1cb%22}



8.)
curl -F 'access_token={ACCESS_TOKEN_GENERATED_FROM_STEP_6}' \
-F 'message={MESSAGE}' \
-F 'link={HYPER_LINK}' \
-F 'picture={IMAGE}' \
-F 'name={IMAGE_NAME}' \
-F 'caption={IMAGE_CAPTION}' \
-F 'description={DESCRIPTION}' \
-F 'actions={JSON_ENCODED_STRING_FOR_EXTRA_HYPERLINKS}' \
https://graph.facebook.com/{PAGE_ID}/feed

e.g.

curl -F 'access_token=303409109772222|60ad2f9f47cdaf5e03176824-100000098944650|121364427524405|LDf-47eJi-dYgjourPlz4Kp78Jg' \
-F 'message=Message \
-F 'link=http://www.link.com \
-F 'picture=http://link.com/story.jpg' \
-F 'name=Name \
-F 'caption=Caption \
-F 'description=Description \
-F 'actions={"name": "Caption1", "link": "http://link.com"}' \
https://graph.facebook.com/121364427524405/feed

* Note: On success it will return JSON_ENCODED_STRING with post-id as id


Reference:-

http://developers.facebook.com/docs/reference/api/post/

http://www.fbsmm.com/2010/12/04/simple-example-to-post-on-facebook-wall-using-php/

Monday, November 22, 2010

Error while working with Zend Framework application.ini resources.layout.pluginClass = ‘xxxxxx’

Hi Folks!

I came across an interesting problem while working with Zend Framework module based implementation.

To enable module based layout I followed the very good post by Ponders.

But rather than loading class in Bootstrap.php I defined in applicatio.ini.

I made following changes in application.ini :-

resources.layout.pluginClass = 'Plugin_ModuleLayout'

Code was working fine on my machine but when my colleague checked out the version things were broken and the error message displayed was

Zend_Exception: Security check: Illegal character in filename in /path/to/Zend/library/Zend/Loader.php on line 303

After lot of head scratching I came to know that it was single-quote (') that was culprit. When I modified application.ini like

resources.layout.pluginClass = Plugin_ModuleLayout

things started working and I was able to apply module based layout.

Even we can use double quotes (") like this :-
resources.layout.pluginClass = "Plugin_ModuleLayout"

I think PHP version created some problem.

I was running PHP 5.3.2 and my colleague was working on 5.2.x.

Word of caution : Avoid use of quotes in application.ini.

Hopefully I will be able to help someone and save few precious minutes.