Skip to content

Instantly share code, notes, and snippets.

@patrickmaciel
Created May 5, 2013 22:33
Show Gist options
  • Save patrickmaciel/5522459 to your computer and use it in GitHub Desktop.
Save patrickmaciel/5522459 to your computer and use it in GitHub Desktop.
Tentando conectar no Facebook SDK PHP
<?php
/**
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
require 'facebook/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => '132820276910194',
'secret' => '1c1a66c9a520fa0e8abdee80294cdcc3',
'cookie' => true
));
// Get User ID
$user = $facebook->getUser();
echo '<pre>'; print_r($user); echo '</pre>';exit;
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array('scope' => 'email,publish_stream,manage_pages'));
}
$access_token = $facebook->getAccessToken();
$attachment = array(
'access_token' => $access_token,
'message' => "Test with Facebook SDK for PHP",
'name' => "Patrick Maciel",
'description' => "Just a test",
'link' => "http://www.patrickmaciel.com",
'picture' => ""
);
try{
$post_id = $facebook->api("/iniciativa3det/feed","POST",$attachment);
}catch(Exception $e){
echo '<pre>'; print_r($e->getMessage()); echo '</pre>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment