1 Installation
- Go to the Facebook developer’s page http://www.facebook.com/developers/createapp.php and create new application. And get api_key and secret_key of your application.
- Fill fields Connect URL, Post-Authorize Redirect URL and Post-Authorize URL with url to your site which will callback after user registration and which will get GET data from Facebook with user session_key, secret_key, sig and user_id which will be used for user authentication in future.
2 Understanding of Facebook API methods
Download Facebook API library for PHP from http://svn.facebook.com/svnroot/platform/clients/packages/facebook-platform.tar.gz
Here is example of how code is work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| include_once(“facebook/facebook.php"); //path to the facebook library
$facebook = new Facebook($api_key, secret_key); //api and secret key of your application which you get in chapter 1.1
$facebook->set_user($session_key, $secret_key, $sig) //session_key, secret_key and sig of user which you get after user registered your Facebook application in chapter 1.2
do {
switch($data['type']) {
case "post_photos":
foreach($data['file'] as $file) {
$res = $facebook->api_client->photos_upload($file['tmp_name'],null,$data['title'],$conf['userid']);
}
break;
case "post_status":
$res = $facebook->api_client->users_setStatus($data['message'],$conf['userid']);
break;
case "post_blog":
$res = $facebook->api_client->notes_create($data['title'],$data['message'],$conf['userid']);
break;
case "post_microblog":
$res = $facebook->api_client->stream_publish($data['message'],$data['attachment'],$data['links'],$conf['userid'],$conf['userid']);
break;
default:
break;
}
} while(!$res); |
There is 4 types of posting on facebook, each of them has specific function
Posting photos:
$facebook->api_client->photos_upload($file['tmp_name'],null,$title,$user_id);
- $file['tmp_name'] – path to the image on server filesystem
- $title – title of photo
- $user_id – user on whose wall photo will be posted. By default it’s must be user_id of user who post a photo(to post on his wall)
Posting status:
$facebook->api_client->users_setStatus($message,$user_id);
- $message – status message
- $user_id – user on whose wall photo will be posted. By default it’s must be user_id of user who post a photo(to post on his wall)
Posting blog:
$facebook->api_client->notes_create($title,$’message,$user_id);
- $title – title of post
- $message – post message
- $user_id – user on whose wall photo will be posted. By default it’s must be user_id of user who post a photo(to post on his wall)
Posting stream:
$facebook->api_client->stream_publish($message,$attachment,$links,$user_id_target,$userid_actor);
- $message – post message
- $user_id_target – id of user on whose wall posting
- $userid_actor – id of user who posting
Attachments and link example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| $attachment = array(
'name' => 'ninja cat',
'href' => 'http://www.youtube.com/watch?v=muLIPWjks_M',
'caption' => '{*actor*} uploaded a video to www.youtube.com',
'description' => 'a sneaky cat',
'properties' => array('category' => array(
'text' => 'pets',
'href' => 'http://www.youtube.com/browse?s=mp&t=t&c=15'),
'ratings' => '5 stars'),
'media' => array(array('type' => 'video',
'video_src' => 'http://www.youtube.com/v/fzzjgBAaWZw&hl=en&fs=1',
'preview_img' => 'http://img.youtube.com/vi/muLIPWjks_M/default.jpg?h=100&w=200&sigh=__wsYqEz4uZUOvBIb8g-wljxpfc3Q=',
'video_link' => 'http://www.youtube.com/watch?v=muLIPWjks_M',
'video_title' => 'ninja cat')));
$links = array(
array('text' => 'Upload a video',
'href' => 'http://www.youtube.com/my_videos_upload')); |
And one more thing. There can be trouble with connection to the Facebook API server so in example was used a loop which can repeat calling Facebook API until get an unswer from it.
Hope this helps.
Часть 1
Короче немного доделал этот примерчик. Появились следующие фичи:
- Добавление списка меток(возможность переключатся на метки через список)
- Удаление меток(в том числе и через список)
- Добавлен поиск с учетом ограничения сектора
- Добавлены подсказки для поиска при множественном совпадении
В планах сделать:
- Редактирование меток
- Переделать UI(Есть небольшие глюки)
- Добавить поиск по списку меток
- Добавить категории для меток
- Написать бек-энд для хранения всей инфы, включая разделение на пользователи.
Сам пример смотреть здесь
Вчера копался с Google Maps API, так как выяснил, что они наконец то добавили карту Киева(до этого юзал Mapia, но там API шо из задницы). Решил вот сделать небольшой примерчик ее использования.
В примере расмотренно:
- Ограничение области показа карты
- Ограничение увеличения в зависимости от типа карты
- Настройка UI
- Добавление собственых контролов
- Работа с урл(парсинг координат в урл и обратно)
- Поддержка истории
- Работа с событиями
- Работа с маркерами и менеджером маркеров
Код выкладывать небуду по ненадобности, заходим и жмем Ctrl + U (и код ваш)
Зырим здесь