my code stock.com

pascalwacker

Tutorial Part 2.3 - Example
by pascalwacker

JS Example

Snippet options

Download: Download snippet as tutorial-part-23-example.php.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

<?php
// You may ask for what do i need that ready function? We load the JS async that means we're not 100% sure that it's loaded when the dom is loaded therefore we need a function. You also can use FB.login() or FB.logout() and so on in this just to make sure FB is ready!
// Du fragst dich vileicht was bringt mir diese ready Funktion? Da wir das JS async laden sind wir nicht 100% sicher, dass es bereit ist wenn der dom geladen ist und um dies zu testen brauchen wir die Funktion. Du kannst ebenfalls FB.login() oder FB.logout() und so weiter in der fbEnsureInit Funktion aufrufen um sicher zu stellen dass FB bereit ist.
?>
<script type="text/javascript">
jQuery(document).ready(function($){
	<?
	// You need your instance of Facebook from "Tutorial Part 1" here... for example with ZEND you load it like this (if you saved it as i said!)
	// Du benötigst deine PHP Instanz von Facebook hier aus "Tutorial Part 1"... Mit ZEND wird sie z.B. so geladen (wenn du sie wie angegeben gespeichert hast!)
	// $facebook = Zend_Registry::get('facebook');
	
	// Get the list of all permissions the app has
	// Holt die Liste aller Berechtigungen
	$permissions = $facebook->api("/me/permissions");
	if( array_key_exists('create_event', $permissions['data'][0]) ): ?>
		/* If permission is granted continue
		Falls berechtigung erteilt wurde fortfahren */
		doStuf();
	<? else: ?>
		/* Else request permission
		Sonst berechtigung anfordern */
		fbEnsureInit(function() {
			FB.ui({
				method: 'permissions.request',
				perms: 'create_event'
			},function(response) {
				if (response && response.perms) {
					doRequest();
				} else if (!response.perms){
					alert('Permission not granted, can not move on');
					alert('Berechtigung nicht erteilt, kann nicht fortfahren')
				}
			});
		});
	<? endif; ?>
});

function doStuf() {
	alert("You've got the permission");
	alert("Benötige Berechtigungen vorhanden");
}
</script>

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.