rest-graph

Tutorial on setting up a sample Facebook application with Rails 3
and RestGraph could be found on samplergthree. Instead, if you're
an experienced Ruby programmer, you might also want to look at
detailed documents.

LINKS:

DESCRIPTION:

A lightweight Facebook Graph API client

We have moved the development from rest-graph to rest-more.
From now on, we would only fix bugs in rest-graph rather than adding
features, and we would only backport important changes from rest-more
once in a period. If you want the latest goodies, please see rest-more
Otherwise, you can stay with rest-graph with bugs fixes.

FEATURES:

Simple Graph API call

Simple FQL call

Utility to extract access_token and check sig in cookies/signed_request

REQUIREMENTS:

Tested with MRI 1.8.7 and 1.9.2 and Rubinius 1.2.2.
Because of development gems can't work well on JRuby,
let me know if rest-graph is working on JRuby, thanks!

QUICK START:

Obtaining an access token

If you are using Rails, we recommend that you include a module called
RestGraph::RailsUtil into your controllers. (Your code contributions
for other Ruby frameworks would be appreciated!). RestGraph::RailsUtil
adds the following two methods to your controllers:

rest_graph_setup: Attempts to find an access_token from the environment
and initializes a RestGraph object with it.
Most commonly used inside a filter.
rest_graph: Accesses the RestGraph object by rest_graph_setup.

Example usage:

classMyController<ActionController::BaseincludeRestGraph::RailsUtilbefore_filter:setupdefmyaction@medata=rest_graph.get('me')endprivatedefsetuprest_graph_setup(:app_id=>'123',:canvas=>'mycanvas',:auto_authorize_scope=>'email')# See below for more options
endend

Default setup

New RestGraph objects can read their default setup configuration from a
YAML configuration file. Which is the same as passing to rest_graph_setup.

post

fql

fql_multi

rg.fql_multi(:q1=>'SELECT name FROM page WHERE page_id="123"',:q2=>'SELECT name FROM page WHERE page_id="456"')

old_rest

Call functionality from Facebook's old REST API:

rg.old_rest('stream.publish',{:message=>'Greetings',:attachment=>{:name=>'Wikipedia',:href=>'http://wikipedia.org/',:caption=>'Wikipedia says hi.',:media=>[{:type=>'image',:src=>'http://wikipedia.org/logo.png',:href=>'http://wikipedia.org/'}]}.to_json,:action_links=>[{:text=>'Go to Wikipedia',:href=>'http://wikipedia.org/'}].to_json},:auto_decode=>false)# You'll need to set auto_decode to false for
# this API request if Facebook is not returning
# a proper formatted JSON response. Otherwise,
# this could be omitted.
# Some Old Rest API requires a special access token with app secret
# inside of it. For those methods, use secret_old_rest instead of the
# usual old_rest with common access token.
rg.secret_old_rest('admin.getAppProperties',:properties=>'app_id')

Utility Methods:

parse_???

All the methods that obtain an access_token will automatically save it.

If you have the session in the cookies,
then RestGraph can parse the cookies:

rg.parse_cookies!(cookies)

If you're writing a Rack application, you might want to parse
the session directly from Rack env:

rg.parse_rack_env!(env)

access_token

rg.access_token

Data associated with the access_token (which might or might not
available, depending on how the access_token was obtained).

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.