YaWK  24.1
Yet another WebKit
YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample Class Reference

Facebook Graph API explorer widget - for demo and development purpose only! More...

Public Member Functions

 __construct ($db)
 
 basicOutput ()
 
 checkAccessToken ()
 
 checkApiObjectData ()
 
 checkAppId ()
 
 checkPageId ()
 
 checkRequirements ()
 
 drawGallery ()
 
 loadJSSDK ()
 
 makeApiCall ()
 
 printApiObject ()
 

Public Attributes

 $apiObject
 
 $fbExampleAccessToken = ''
 
 $fbExampleAppId = ''
 
 $fbExampleEndDate = ''
 
 $fbExampleFields = 'id,name,description,place,start_time,cover,maybe_count,attending_count,is_canceled'
 
 $fbExampleGraphRequest = '/events/'
 
 $fbExamplePageId = ''
 
 $fbExampleStartDate = ''
 
 $fbExampleType = 'future'
 
 $fbExampleYearRange = '1'
 
 $jsSDKLoaded = 'false'
 
 $sinceDate = ''
 
 $untilDate = ''
 

Detailed Description

Facebook Graph API explorer widget - for demo and development purpose only!

Use Facebook Graph API to get any data from a Facebook Page. Require App ID and Access Token.

This is just an empty example widget for development and demo purpose!

It is recommended to play around with the facebook graph explorer. You can set any api call and fields you like to play around and explore the resulting array. You can use this widget as base for your own facebook api projects.

Author
Daniel Retzl danie.nosp@m.lret.nosp@m.zl@gm.nosp@m.ail..nosp@m.com
Version
1.0.0

Definition at line 17 of file fbExample.php.

Constructor & Destructor Documentation

◆ __construct()

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::__construct (   $db)

Definition at line 47 of file fbExample.php.

49  {
50  // load this widget settings from db
51  $widget = new \YAWK\widget();
52  $settings = $widget->getWidgetSettingsArray($db);
53  foreach ($settings as $property => $value)
54  {
55  $this->$property = $value;
56  }
57  // check if required settings are set
58  $this->checkRequirements();
if(isset($_POST['save'])) $settings
$value

References $db, $settings, $value, and YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\checkRequirements().

Member Function Documentation

◆ basicOutput()

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::basicOutput ( )

Definition at line 265 of file fbExample.php.

267  {
268  $this->loadJSSDK();
269  $this->makeApiCall();
270 
271  foreach ($this->apiObject['data'] as $property => $value) {
272  echo "<b>$property </b>: $value<br>";
273 
274  foreach ($value as $entry => $key) {
275 
276  echo "$entry : $key<br>";
277 
278  if (is_array($key)) {
279  foreach ($key as $p => $v) {
280  echo "&nbsp;&nbsp;&nbsp;&nbsp;$p : $v<br>";
281  if (is_array($v)) {
282  foreach ($v as $a => $b) {
283  echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$a : $b<br>";
284  }
285  }
286  }
287  }
288  }
289  echo "<br>";
290  }

References $value, YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\loadJSSDK(), and YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\makeApiCall().

◆ checkAccessToken()

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::checkAccessToken ( )

Definition at line 86 of file fbExample.php.

88  {
89  if (isset($this->fbExampleAccessToken) && (!empty($this->fbExampleAccessToken)))
90  {
91  if (is_string($this->fbExampleAccessToken))
92  {
93  return true;
94  }
95  else
96  {
97  die ("Access token is set, but not a string value! Please check your access token.");
98  }
99  }
100  else
101  {
102  die ("Access token is not set. Please add your access token. You can obtain it from http://developers.facebook.com");
103  }
die
Definition: block-user.php:27

References die.

Referenced by YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\checkRequirements().

◆ checkApiObjectData()

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::checkApiObjectData ( )

Definition at line 235 of file fbExample.php.

237  {
238  if (isset($this->apiObject['data']) && (!empty($this->apiObject['data'])))
239  {
240  return true;
241  }
242  else
243  {
244  return false;
245  }

Referenced by YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\printApiObject().

◆ checkAppId()

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::checkAppId ( )

Definition at line 67 of file fbExample.php.

69  {
70  if (isset($this->fbExampleAppId) && (!empty($this->fbExampleAppId)))
71  {
72  if (is_numeric($this->fbExampleAppId))
73  {
74  return true;
75  }
76  else
77  {
78  die ("app ID is set, but not a numeric value! Please check your app ID - it should contain numbers only.");
79  }
80  }
81  else
82  {
83  die ("app ID is not set. Please add your app ID. You can obtain it from http://developers.facebook.com");
84  }

References die.

Referenced by YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\checkRequirements(), and YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\loadJSSDK().

◆ checkPageId()

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::checkPageId ( )

Definition at line 104 of file fbExample.php.

106  {
107  if (isset($this->fbExamplePageId) && (!empty($this->fbExamplePageId)))
108  {
109  if (is_string($this->fbExamplePageId))
110  {
111  return true;
112  }
113  /* to allow custom url requests, this is uncommented.
114  else
115  {
116  die ("Page ID is set, but not a string value! Please check your page ID.");
117  }
118  */
119  }
120  /* to allow custom url requests, this is uncommented.
121  else
122  {
123  die ("Page ID is not set. Please add your page ID. The Page ID is: https://www.facebook.com/{YOURPAGEID}");
124  }
125  */

Referenced by YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\checkRequirements().

◆ checkRequirements()

◆ drawGallery()

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::drawGallery ( )

Definition at line 292 of file fbExample.php.

294  {
295  $this->loadJSSDK();
296  $this->makeApiCall();
297  if (isset($this->apiObject['data']) && (!empty($this->apiObject))) {
298  echo "<h1>Facebook Photo Albums</h1>";
299 
300  foreach ($this->apiObject['data'] as $property => $value)
301  {
302  if ($value['name'] != "//Profile Pictures"
303  && ($value['name'] !=
304  != "//Cover Photos")
305  {
306  $fn = $value['picture']['data']['url'];
307  echo "<div class=\"col-md-2 text-center\">
308  <img src=\"$fn\" style=\"width:200px;\" class=\"img-responsive hvr-grow\"><h3>$value[name]
309  <small><i>($value[count])</i></small></h3><br>
310  </div>";
311 
312 
313  }
314 
315  /*
316  foreach ($value['images'] as $photo)
317  {
318  echo "<pre>";
319  echo "<img src=\"".$photo['source']."\" class=\"img-responsive\">";
320  echo "</pre>";
321  }
322  */
323 /*
324  echo "<br><br>$property : $value<br>";
325 
326  if (is_array($value)) {
327 
328  foreach ($value as $entry => $key) {
329  echo "$entry : $key <br>";
330  if (is_array($key)) {
331  foreach ($key as $image) {
332  echo "$key : $image<br>";
333  if (is_array($key) || (is_array($image))) {
334  foreach ($key as $arrayKey => $arrayValue) {
335  echo "&nbsp;&nbsp;$arrayKey : $arrayValue<br>";
336  if (is_array($arrayValue)) {
337  foreach ($arrayValue as $p => $v) {
338  echo "&nbsp;&nbsp;$p : $v<br>";
339  }
340  }
341  }
342  }
343  }
344  }
345  }
346  }
347 */
348  }
349  }

References $value, YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\loadJSSDK(), and YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\makeApiCall().

◆ loadJSSDK()

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::loadJSSDK ( )

Definition at line 127 of file fbExample.php.

129  { // check if fb JS SDK was loaded before
130  if ($this->jsSDKLoaded == 'false')
131  { // check if app ID is set
132  if ($this->checkAppId() == true)
133  {
134  // include facebook SDK JS
135  echo "<script>
136  window.fbAsyncInit = function() {
137  FB.init({
138  appId : '" . $this->fbExampleAppId . "',
139  xfbml : true,
140  version : 'v3.1'
141  });
142  FB.AppEvents.logPageView();
143  };
144 
145  (function(d, s, id){
146  var js, fjs = d.getElementsByTagName(s)[0];
147  if (d.getElementById(id)) {return;}
148  js = d.createElement(s); js.id = id;
149  js.src = \"https://connect.facebook.net/en_US/sdk.js\";
150  fjs.parentNode.insertBefore(js, fjs);
151  }(document, 'script', 'facebook-jssdk'));
152  </script>";
153  $this->jsSDKLoaded = 'true';
154  }
155  else
156  {
157  die ("unable to include facebook js SDK - checkAppId failed. Please check your app ID in the widget settings!");
158  }
159  }

References YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\checkAppId(), and die.

Referenced by YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\basicOutput(), and YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\drawGallery().

◆ makeApiCall()

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::makeApiCall ( )

Definition at line 161 of file fbExample.php.

163  {
164  // WHICH EVENTS TO DISPLAY?
165  // evaluation of event type select field
166  if ($this->fbExampleType == "all")
167  {
168  // ALL EVENTS (FUTURE + PAST)
169  $this->sinceDate = date('Y-01-01', strtotime('-' . $this->fbExampleYearRange . ' years'));
170  $this->untilDate = date('Y-01-01', strtotime('+' . $this->fbExampleYearRange . ' years'));
171  }
172  elseif ($this->fbExampleType == "future")
173  {
174  // UPCOMING EVENTS
175  $this->sinceDate = date('Y-m-d');
176  $this->untilDate = date('Y-12-31', strtotime('+' . $this->fbExampleYearRange . ' years'));
177  }
178  elseif ($this->fbExampleType == "past")
179  {
180  // PAST EVENTS
181  $this->sinceDate = date('Y-01-01', strtotime('-' . $this->fbExampleYearRange . ' years'));
182  $this->untilDate = date('Y-m-d');
183  }
184  else
185  { // IF NOT SET - use default:
186  // UPCOMING EVENTS
187  $this->sinceDate = date('Y-m-d');
188  $this->untilDate = date('Y-12-31', strtotime('+' . $this->fbExampleYearRange . ' years'));
189  }
190 
191  // IF START + END DATE IS SET
192  if (isset($this->fbExampleStartDate) && (!empty($this->fbExampleStartDate))
193  && (isset($this->fbExampleEndDate) && (!empty($this->fbExampleEndDate))))
194  {
195  $this->sinceDate = date($this->fbExampleStartDate);
196  $this->untilDate = date($this->fbExampleEndDate);
197  }
198 
199  // unix timestamp years
200  $since_unix_timestamp = strtotime($this->sinceDate);
201  $until_unix_timestamp = strtotime($this->untilDate);
202  // check if pageID is set
203  if (isset($this->fbExamplePageId) && (!empty($this->fbExamplePageId)))
204  {
205  // set markup for pageID string
206  $pageIdMarkup = "{$this->fbExamplePageId}";
207  }
208  else
209  { // leave empty if no page id is given (to build custom graph string)
210  $this->fbExamplePageId = '';
211  }
212  // check if fields are set
213  if (isset($this->fbExampleFields) && (!empty($this->fbExampleFields)))
214  { // set markup for api query string
215  $fieldsMarkup = "&fields={$this->fbExampleFields}";
216  if (empty($this->fbExamplePageId))
217  {
218  $fieldsMarkup = "?fields={$this->fbExampleFields}";
219  }
220  }
221  else
222  { // no fields wanted, leave markup empty
223  $fieldsMarkup = '';
224  }
225 
226  // prepare API call
227  // $json_link = "https://graph.facebook.com/v2.7/{$this->fbExamplePageId}{$this->fbExampleGraphRequest}?fields={$this->fields}&access_token={$this->fbExampleAccessToken}";
228  $json_link = "https://graph.facebook.com/v3.1/{$this->fbExamplePageId}{$this->fbExampleGraphRequest}?access_token={$this->fbExampleAccessToken}&since={$since_unix_timestamp}&until={$until_unix_timestamp}" . $fieldsMarkup . "";
229  // get json string
230  $json = file_get_contents($json_link);
231 
232  // convert json to object
233  return $this->apiObject = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);
print $tourdates date

References date.

Referenced by YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\basicOutput(), YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\drawGallery(), and YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\printApiObject().

◆ printApiObject()

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::printApiObject ( )

Definition at line 247 of file fbExample.php.

249  {
250  $this->makeApiCall();
251  if ($this->checkApiObjectData() === true)
252  {
253  echo "<pre>";
254  print_r($this);
255  echo "</pre>";
256  }
257  else
258  {
259  echo "<pre>";
260  echo "Could not retrieve any data from Facebook. Please check your PageID, API request, field and date settings";
261  echo "</pre>";
262  exit;
263  }
exit

References YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\checkApiObjectData(), exit, and YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample\makeApiCall().

Member Data Documentation

◆ $apiObject

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::$apiObject
Parameters
objectapi result (as object)

Definition at line 44 of file fbExample.php.

◆ $fbExampleAccessToken

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::$fbExampleAccessToken = ''
Parameters
stringyour access token (secret word from developers.facebook.com)

Definition at line 24 of file fbExample.php.

◆ $fbExampleAppId

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::$fbExampleAppId = ''
Parameters
stringyour app ID (from developers.facebook.com)

Definition at line 20 of file fbExample.php.

◆ $fbExampleEndDate

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::$fbExampleEndDate = ''
Parameters
stringuser defined end date

Definition at line 34 of file fbExample.php.

◆ $fbExampleFields

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::$fbExampleFields = 'id,name,description,place,start_time,cover,maybe_count,attending_count,is_canceled'
Parameters
stringfields that should be selected from facebook graph

Definition at line 28 of file fbExample.php.

◆ $fbExampleGraphRequest

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::$fbExampleGraphRequest = '/events/'
Parameters
stringyour graph request

Definition at line 26 of file fbExample.php.

◆ $fbExamplePageId

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::$fbExamplePageId = ''
Parameters
stringyour page ID (http://facebook.com/{YOURPAGEID}

Definition at line 22 of file fbExample.php.

◆ $fbExampleStartDate

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::$fbExampleStartDate = ''
Parameters
stringuser defined start date

Definition at line 32 of file fbExample.php.

◆ $fbExampleType

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::$fbExampleType = 'future'
Parameters
stringwhich events should be shown? future|past|all

Definition at line 36 of file fbExample.php.

◆ $fbExampleYearRange

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::$fbExampleYearRange = '1'
Parameters
stringshow events of this time range

Definition at line 30 of file fbExample.php.

◆ $jsSDKLoaded

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::$jsSDKLoaded = 'false'
Parameters
stringtrue|false was the js SDK loaded?

Definition at line 42 of file fbExample.php.

◆ $sinceDate

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::$sinceDate = ''
Parameters
stringevents since this date (used for calc)

Definition at line 38 of file fbExample.php.

◆ $untilDate

YAWK\WIDGETS\FACEBOOK\EXAMPLE\fbExample::$untilDate = ''
Parameters
stringevents until this date (used for calc)

Definition at line 40 of file fbExample.php.


The documentation for this class was generated from the following file: