DEPRECATION WARNING

This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

EXT: Post TYPO3 records to Facebook

Created:2010-02-18T17:33:18
Changed by:Manfred Egger
Changed:2012-03-26T12:53:31.130000000
Classification:bc_post2facebook
Description:The keywords help with categorizing and tagging of the manuals. You can combine two or more keywords and add additional keywords yourself. Please use at least one keyword from both lists. If your manual is NOT in english, see next tab "language" ---- forEditors (use this for editors / german "Redakteure") forAdmins (use this for Administrators) forDevelopers (use this for Developers) forBeginners (manuals covering TYPO3 basics) forIntermediates (manuals going into more depth) forAdvanced (covering the most advanced TYPO3 topics) see more: http://wiki.typo3.org/doc_template#tags ----
Keywords:facebook, forEditors, forAdmins
Author:Bluechip Software
Email:http://www.bluechip.at
Info 4:
Language:en

img-1 img-2 EXT: Post TYPO3 records to Facebook - bc_post2facebook

EXT: Post TYPO3 records to Facebook

Extension Key: bc_post2facebook

Language: en

Keywords: facebook, forEditors, forAdmins

Copyright 2000-2010, Bluechip Software, < http://www.bluechip.at>

This document is published under the Open Content License

available from http://www.opencontent.org/opl.shtml

The content of this document is related to TYPO3

- a GNU/GPL CMS/Framework available from www.typo3.org

Table of Contents

EXT: Post TYPO3 records to Facebook 1

`Introduction 3 <#__RefHeading__8934_453505048>`_

What does it do? 3

Screenshots 3

`Users manual 5 <#__RefHeading__8946_453505048>`_

Installation 5

Quickstart 5

1. Create a Facebook App 5

2. Request authorization code 5

3. Complete the extension configuration 6

4. Optional: add the application to your pages 6

`Administration 7 <#__RefHeading__8952_453505048>`_

Page / User TSconfig reference 7

mod.web_modules.bc_post2facebook 7

Configuration of the TYPO3 records 7

`Usage 9 <#__RefHeading__9010_453505048>`_

`Tutorial 10 <#__RefHeading__9012_453505048>`_

`Known problems 12 <#__RefHeading__9014_453505048>`_

`To-Do list 13 <#__RefHeading__9016_453505048>`_

`ChangeLog 14 <#__RefHeading__9018_453505048>`_

Introduction

What does it do?

This extension posts records out from TYPO3 to Facebook.

This extension has been created by Bluechip Software GmbH . An overview for editors can be found on http://www.bluemedia.at/post2facebook/ (in german).

|img-3|

Screenshots

Backend wizard:

img-4

Succesfull wall post on Facebook:

img-5

Users manual

Installation

Install the extension via the extension manager and fill out the necessary fields in the extension config.

Quickstart

1. Create a Facebook App

Go to http://www.facebook.com/developer then create new application and fill in the necessary information

2. Request authorization code

First you need to know which permissions you have to request to get a working extension. Here are some examples:

  • post to the users wall: publish_stream
  • post to a page-wall: publish_stream,manage_pages
  • post to a page- or group-wall: publish_stream,manage_pages,user_groups

Get a full listing of all available permission flags at http://developers.facebook.com/docs/authentication/permissions/

As of the former “offline_access” permission is deprecated and will be removed in future, you shouldn't add this permission to your config anymore. Instead of this, the extension extends the expiration of the auth token every time it is used.

There are two ways to get the authorization code:

Via the wizard in the extension configuration

Manually (usefull if you have to configure the plugin for several users)

Request authorization code via the wizard

You need a valid extension configuration. For this you have to insert the application ID, the application secret and the application Url of your previously created Facebook App and the permissions. If all is well configured you get a warning message, that there is no auth token. You only have to click on the provided link and allow the application to access the needed data.

img-6 Then you are redirected to your applications canvas page. The next step is similar to the manual code request.

Request authorization code manually

Goto https://www.facebook.com/dialog/oauth?client_id=<YOUR_APP_ID>& redirect_uri=<YOUR_REDIRECT_URI>&scope=<YOUR_PERMISSIONS>&state=<S OME_ARBITRARY_BUT_UNIQUE_STRING>

After you login and allow the application you will redirect to your redirect url with the authorization code like

<YOUR_URL>?code=AQCXL0ahfaadfh[...]Uh3C6FoUORw#_=_

Copy the code at the right side of “=” sign (highlighted in red) to paste in extension configuration

Note:

If you remove this application from your profile application setting, and you add the application again then you have to generate this code again.

Note: Allthough the auth code expiration is extended everytime you use the extension, there are some reasons why the token can get invalid:

The token expires after expire time (only if you rarely use the extension)

Yout/the user changes her password which invalidates the access token

You/the user de-authorizes your app

In these cases you have to generate the token again.

3. Complete the extension configuration

Fill out all necessary fields in the extension configuration. To post TYPO3 records you have to configure the TypoScript of the extension for the database table. A standard configuration for tt_news is included, for further information have a look at the Administration section below.

4. Optional: add the application to your pages

If you want to post to your pages you have to add your application to your page.

Administration

Page / User TSconfig reference

Most of the settings made in the extension configuration can be overridden via Page and User Tsconfig.

mod.web_modules.bc_post2facebook
appId

Property

appId

Data type

String

Description

Alternative id of your Facebook App

secret

Property

secret

Data type

String

Description

Alternative secret of your Facebook App

authToken

Property

authToken

Data type

String

Description

Alternative authentication token for your Facebook App

pageId

Property

pageId

Data type

String

Description

Alternative default id of the Facebook page you want to post to

postAsPage

Property

postAsPage

Data type

String keyword

Description

Set to “yes” to enable posting as page

Set to “no” to post as user

groupId

Property

groupId

Data type

String

Description

Alternative default id of the Facebook groupyou want to post to

webUrl

Property

webUrl

Data type

String

Description

Alternative base url for images and links

displayListing

Property

displayListing

Data type

list

Description

With this option you can specify which options the user has to select the location where to post to Facebook. There are the following options available:

  • all: all available pages, groups and the profile are shown
  • none: the user has no options. In this case the pageId or groupId are used as target. If both are not set, the profile is used
  • profile: show the option to post to the profile
  • pages: show all pages
  • groups: show all groups

Example:

mod.web_modules.bc_post2facebook.displayListing = groups, profile

The options “pages” and “groups” can be configured more specific: you can add a list of page or group ids between two curly brackets.

Example:

mod.web_modules.bc_post2facebook.displayListing = groups{1234, 5678}, pages{9876, 5432}
config

Property

config

Data type

Array

Description

Configuration of the TYPO3 records where posting is enabled

config.record_table_name

Property

config.record_table_name

Data type

Array

Description

Configuration of one record

config.record_table_name._config.picture_field

Property

config.record_table_name._config.picture_field

Data type

String

Description

If you want to post an image to Facebook, specify, in which field of the TYPO3 record the image is saved

config.record_table_name._config.picture_as_upload

Property

config.record_table_name._config.picture_as_upload

Data type

Boolean

Description

If set, pictures are not posted with their urls but as uploads (useful for events)

config.record_table_name._config.postAs

Property

config.record_table_name._config.postAs

Data type

String

Description

Specify in which path of the Facebook Graph API you want to post. To post to the wall enter “feed”, to post to the events enter “events”.

More informations at http://developers.facebook.com/docs/reference/api/

config.record_table_name.api_items

Property

config.record_table_name.api_items

Data type

CObj

Description

Use the name of the GraphAPI item as key and configure it as Cobject.

Example:

picture = IMG_RESOURCE
picture {
        file {
                import = uploads/pics/
                import.field = image
                import.listNum.stdWrap.data = register: picture_num
                maxW = 120
                maxH = 120
        }
}

[tsconfig:mod.web_modules.bc_post2facebook]

Configuration of the TYPO3 records

The extension offers the possibility to post almost all TYPO3 records to almost all channels on Facebook, which are available via the GraphAPI. The extension already comes with a configuration for tt_news, use this as reference.

To make the extensions wizard available for other records, follow the steps below:

((generated))
1. Add a new field “tx_bcpost2facebook_facebook_id“ to the database table of your record

Example:

CREATE TABLE tt_news (
        tx_bcpost2facebook_facebook_id tinytext
);
2. Add the TCA configuration to your extensions ext_tables.php or the extTables.php located in typo3conf

Example:

$tempColumns = array(
     'tx_bcpost2facebook_facebook_id' => array(
             'exclude' => 1,
             'label' => 'LLL:EXT:bc_post2facebook/locallang_db.xml:tt_news.tx_bcpost2facebook_facebook_id',
             'config' => array(
                     'type' => 'user',
                     'userFunc' => 'tx_bc_post2facebook_fieldtype->user_TCAform_facebook',
                     'wizards' => Array(
                             '_PADDING' => 2,
                             'link' => Array(
                                     'type' => 'popup',
                                     'title' => 'Post News to Facebook',
                                     'icon' => 'EXT:bc_post2facebook/res/icon_wizard.png',
                                     'script' => 'EXT:bc_post2facebook/lib/class.tx_bc_post2facebook_wizard.php',
                                     'JSopenParams' => 'height=630,width=650,status=0,menubar=0,scrollbars=1',
                             ),
                     ),
             ),
     ),
);

t3lib_div::loadTCA('tt_news');
t3lib_extMgm::addTCAcolumns('tt_news', $tempColumns, 1);
t3lib_extMgm::addToAllTCAtypes('tt_news', 'tx_bcpost2facebook_facebook_id;;;;1-1-1');
3. Add the configuration for your record to page or user Tsconfig

Example:

mod.web_modules.bc_post2facebook {
        config {
                tt_news {
                        _config {
                                picture_field = image
                                postAs = feed
                        }

                        name = TEXT
                        name.field = title

                        link = TEXT
                        link {
                                dataWrap = {field:_url}|
                                typolink {
                                        returnLast = url
                                        additionalParams {
                                                field = uid
                                                wrap = &tx_ttnews[tt_news]=|
                                        }
                                }
                        }

                        description = TEXT
                        description {
                                field = short
                                ifEmpty {
                                        field = bodytext
                                        crop = 300 | ... | 1
                                }
                                stripHtml = 1
                        }
                }
        }
}

Usage

If the button for the wizard is well configured it will show up in the edit form of your record. If the record is already posted to Facebook, the checkbox will be checked (B), otherwise not (A). In both cases you can post the record again by simply clicking on the wizard icon.

img-7

The wizard will be opened in an new window where all configured fields will be rendered. All fields can be reviewed, if there are multiple images, you can select the image which should be posted. If it's enabled you can select the posts target (profile, page, group) and by clicking on the button at the bottom, the extension posts the record to Facebook.

img-8

If there is no error, you receive a success message and your record should be visible on Facebook.

img-9

Tutorial

Here I will show, how to configure the extension to post tt_news records as event on Facebook. Because the extension already has the button for the wizard, we can directly go to the configuration step.

We want to post the news as event, so we have to look at the appropriate API documentation: http://developers.facebook.com/docs/reference/api/event/

Here we see, that we need the “create_event” permission, so we have to generate an authentication token, which provides this permission. Have a look at the chapter “ Quickstart ” to learn how to do this. After we got the token, add it to the extension configuration or the Tsconfig:

mod.web_modules.bc_post2facebook.authToken = YOUR_AUTH_TOKEN

Next the API says that events have to be posted to “http://graph.facebook.com/PROFILE_ID/events”. We only need the part after “PROFILE_ID/” so we add “events” to our configuration:

mod.web_modules.bc_post2facebook.config.tt_news {
        _config {
                postAs = events
        }
}

Next we look at the fields we need to successfully publish an event. We need a field start_time, which should be an ISO-8601 formated date or an UNIX timestamp. Because a timestamp is not readable for some users we use the ISO fromat. The data for this field is taken from the datetime field of the news.

mod.web_modules.bc_post2facebook.config.tt_news {
        start_time = TEXT
     start_time {
             field = datetime
             date = c
     }
}

For the end_time we also use the datetime field and add a default of two hours:

mod.web_modules.bc_post2facebook.config.tt_news {
        end_time = TEXT
     end_time {
             field = datetime
             stdWrap.wrap = | +60*60*2
             prioriCalc = intval
             date = c
     }
}

Because there is already a configuration for tt_news you have to deactivate all unwanted fields by setting them to empty or “NONE”. In this case we keep the name, description and picture but remove the link:

mod.web_modules.bc_post2facebook.config.tt_news {
        link =
}

One last thing we need for the event is the picture. Although there is already a working configuration for the picture, we have to take into account, that there is no field for a picture in the GraphAPI. Pictures for events have to be posted as upload. So all you have to do is, to tell the extension that images should be uploaded instead of referenced by an absolute url:

mod.web_modules.bc_post2facebook.config.tt_news {
        _config {
                picture_as_upload = 1
        }
}

If you have your own records and want to define a picture, you have to set the picture_field to tell the extension where it should take the images from.

mod.web_modules.bc_post2facebook.config.tt_news {
        _config {
                picture_field = images
        }
}

That's all, you should have a working configuration to post a news entry as event to Facebook. For completeness, here is the full configuration including the already configured fields by the extension (the added configuration is bold):

mod.web_modules.bc_post2facebook.config.tt_news {
        _config {
                postAs = events
             picture_as_upload = 1
                picture_field = image
        }

        name = TEXT
        name.field = title

        link =

        start_time = TEXT
     start_time {
             field = datetime
             date = c
     }

     end_time = TEXT
     end_time {
             field = datetime
             stdWrap.wrap = | +60*60*2
             prioriCalc = intval
             date = c
     }

        picture = IMG_RESOURCE
        picture {
                file {
                        import = uploads/pics/
                        import.field = image
                        import.listNum.stdWrap.data = register: picture_num
                        maxW = 120
                        maxH = 120
                }
        }

        description = TEXT
        description {
                field = short
                ifEmpty {
                        field = bodytext
                        crop = 300 | ... | 1
                }
                stripHtml = 1
                parseFunc < lib.parseFunc_RTE
        }
}

Known problems

Nothing yet, but we have not tested all use cases or GraphAPI channels

To-Do list

Find a better way to use tslib_content in backend modules. We use a changed version to get a working IMG_RESOURCE. Please let us know, if there is a better solution

ChangeLog

Take a look at the changelog file

img-2 14