<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Creotiv lives here &#187; example</title>
	<atom:link href="http://creotiv.in.ua/tags/example/feed/" rel="self" type="application/rss+xml" />
	<link>http://creotiv.in.ua</link>
	<description>Блог Андрея Никишаева об IT, менеджменте, SEO и фотографии</description>
	<lastBuildDate>Thu, 26 Apr 2012 13:23:05 +0000</lastBuildDate>
	<language>ru</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Simple Facebook API documentation</title>
		<link>http://creotiv.in.ua/%d0%bf%d1%80%d0%be%d0%b3%d1%80%d0%b0%d0%bc%d0%bc%d0%b8%d1%80%d0%be%d0%b2%d0%b0%d0%bd%d0%b8%d0%b5/simple-facebook-api-documentation/</link>
		<comments>http://creotiv.in.ua/%d0%bf%d1%80%d0%be%d0%b3%d1%80%d0%b0%d0%bc%d0%bc%d0%b8%d1%80%d0%be%d0%b2%d0%b0%d0%bd%d0%b8%d0%b5/simple-facebook-api-documentation/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 14:46:17 +0000</pubDate>
		<dc:creator>Андрей Никишаев</dc:creator>
				<category><![CDATA[Программирование]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[social]]></category>

		<guid isPermaLink="false">http://creotiv.in.ua/?p=937</guid>
		<description><![CDATA[Simple example thats show all facebook posting function]]></description>
			<content:encoded><![CDATA[<p><strong>1 Installation</strong></p>
<ol>
<li>Go to the Facebook      developer’s page http://www.facebook.com/developers/createapp.php and      create new application. And get <strong>api_key</strong> and <strong>secret_key</strong> of your      application.</li>
<li>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 <strong>session_key</strong>,      <strong>secret_key</strong>, <strong>sig</strong> and <strong>user_id</strong> which will be used for user authentication in future.</li>
</ol>
<h2>2 Understanding of Facebook API methods</h2>
<p>Download Facebook API library for PHP from <a href="http://svn.facebook.com/svnroot/platform/clients/packages/facebook-platform.tar.gz" target="_blank">http://svn.facebook.com/svnroot/platform/clients/packages/facebook-platform.tar.gz</a></p>
<p>Here is example of how code is work:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span>“facebook<span style="color: #339933;">/</span>facebook<span style="color: #339933;">.</span>php<span style="color: #0000ff;">&quot;);   //path to the facebook library
<span style="color: #006699; font-weight: bold;">$facebook</span> = new Facebook(<span style="color: #006699; font-weight: bold;">$api_key</span>, secret_key);  //api and secret key of your application which you get in chapter 1.1
		<span style="color: #006699; font-weight: bold;">$facebook</span>-&amp;gt;set_user(<span style="color: #006699; font-weight: bold;">$session_key</span>, <span style="color: #006699; font-weight: bold;">$secret_key</span>, <span style="color: #006699; font-weight: bold;">$sig</span>)  //session_key, secret_key and sig of user which you get after user registered your Facebook application  in chapter 1.2
		do {
			switch(<span style="color: #006699; font-weight: bold;">$data</span>['type']) {
				case &quot;</span>post_photos<span style="color: #0000ff;">&quot;:
					foreach(<span style="color: #006699; font-weight: bold;">$data</span>['file'] as <span style="color: #006699; font-weight: bold;">$file</span>) {
						<span style="color: #006699; font-weight: bold;">$res</span> = <span style="color: #006699; font-weight: bold;">$facebook</span>-&amp;gt;api_client-&amp;gt;photos_upload(<span style="color: #006699; font-weight: bold;">$file</span>['tmp_name'],null,<span style="color: #006699; font-weight: bold;">$data</span>['title'],<span style="color: #006699; font-weight: bold;">$conf</span>['userid']);
					}
					break;
				case &quot;</span>post_status<span style="color: #0000ff;">&quot;:
					<span style="color: #006699; font-weight: bold;">$res</span> = <span style="color: #006699; font-weight: bold;">$facebook</span>-&amp;gt;api_client-&amp;gt;users_setStatus(<span style="color: #006699; font-weight: bold;">$data</span>['message'],<span style="color: #006699; font-weight: bold;">$conf</span>['userid']);
					break;
				case &quot;</span>post_blog<span style="color: #0000ff;">&quot;:
					<span style="color: #006699; font-weight: bold;">$res</span> = <span style="color: #006699; font-weight: bold;">$facebook</span>-&amp;gt;api_client-&amp;gt;notes_create(<span style="color: #006699; font-weight: bold;">$data</span>['title'],<span style="color: #006699; font-weight: bold;">$data</span>['message'],<span style="color: #006699; font-weight: bold;">$conf</span>['userid']);
					break;
				case &quot;</span>post_microblog<span style="color: #0000ff;">&quot;:
					<span style="color: #006699; font-weight: bold;">$res</span> = <span style="color: #006699; font-weight: bold;">$facebook</span>-&amp;gt;api_client-&amp;gt;stream_publish(<span style="color: #006699; font-weight: bold;">$data</span>['message'],<span style="color: #006699; font-weight: bold;">$data</span>['attachment'],<span style="color: #006699; font-weight: bold;">$data</span>['links'],<span style="color: #006699; font-weight: bold;">$conf</span>['userid'],<span style="color: #006699; font-weight: bold;">$conf</span>['userid']);
					break;
				default:
					break;
			}
                                     } while(!<span style="color: #006699; font-weight: bold;">$res</span>);</span></pre></div></div>

<p>There is 4 types of posting on facebook, each of them has specific function</p>
<p><strong>Posting photos:</strong></p>
<p><em>$facebook-&gt;api_client-&gt;photos_upload($file['tmp_name'],null,$title,$user_id);</em></p>
<ul>
<li>$file['tmp_name'] – path to the image on server filesystem</li>
<li>$title – title of photo</li>
<li>$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)</li>
</ul>
<p><strong>Posting status:</strong></p>
<p><em>$facebook-&gt;api_client-&gt;users_setStatus($message,$user_id);</em></p>
<ul>
<li>$message – status message</li>
<li>$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)</li>
</ul>
<p><strong>Posting blog:</strong></p>
<p><em>$facebook-&gt;api_client-&gt;notes_create($title,$&#8217;message,$user_id);</em></p>
<ul>
<li>$title – title of post</li>
<li>$message – post message</li>
<li>$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)</li>
</ul>
<p><strong>Posting stream:</strong></p>
<p><em>$facebook-&gt;api_client-&gt;stream_publish($message,$attachment,$links,$user_id_target,$userid_actor);</em></p>
<ul>
<li>$message – post message</li>
<li>$user_id_target – id of user on whose wall posting</li>
<li>$userid_actor – id of user who posting</li>
</ul>
<p>Attachments and link example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$attachment</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'ninja cat'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'href'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'http://www.youtube.com/watch?v=muLIPWjks_M'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'caption'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'{*actor*} uploaded a video to www.youtube.com'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'a sneaky cat'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'properties'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                              <span style="color: #0000ff;">'text'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'pets'</span><span style="color: #339933;">,</span>
                              <span style="color: #0000ff;">'href'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'http://www.youtube.com/browse?s=mp&amp;amp;t=t&amp;amp;c=15'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">'ratings'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'5 stars'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'media'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'video'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'video_src'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'http://www.youtube.com/v/fzzjgBAaWZw&amp;amp;hl=en&amp;amp;fs=1'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'preview_img'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'http://img.youtube.com/vi/muLIPWjks_M/default.jpg?h=100&amp;amp;w=200&amp;amp;sigh=__wsYqEz4uZUOvBIb8g-wljxpfc3Q='</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'video_link'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'http://www.youtube.com/watch?v=muLIPWjks_M'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'video_title'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'ninja cat'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$links</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                      <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'text'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'Upload a video'</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">'href'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'http://www.youtube.com/my_videos_upload'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>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.</p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://creotiv.in.ua/%d0%bf%d1%80%d0%be%d0%b3%d1%80%d0%b0%d0%bc%d0%bc%d0%b8%d1%80%d0%be%d0%b2%d0%b0%d0%bd%d0%b8%d0%b5/simple-facebook-api-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

