In my matrimonial site, i want to add the three functionality, Upload photo from local disk, upload photo and modify photo into pencil sketch, Get photo from facebook account.
i have analyzed and posted created some threads for access FB Photos. but now That suggested code are require the APPId, Security Key. but dont see any where user FB username and password.
Can you please show the right direction for this request. how to access FB photos from my site. From user end we can request only FB username and password.
Right now analyzing towards of this below snippet. even this snippet return 0 values.
now my doubt is, how my APPID will use for accessing others photo album in FB.
require '../src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$config = array();
$config['appId'] = '109181812948600';
$config['secret'] = 'edflmlkmlkmlkmlkmlk7079e9d5884';
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config);
$uid = $facebook->getUser();
echo $uid;
To access profile pictures you need authentication. You can use OAuth.io for easy implementation of OAuth. For more details you can visit their website : https://oauth.io/#/docs
Related
Im getting started with the php sdk, and struggling to understand a few things (I have a basic example below - but everytime the pic goes to MY wall and not the fan page)
Code:
require_once("facebook.php"); // set the right path
$config = array();
$config['appId'] = 'app id';
$config['secret'] = 'app secret';
$config['fileUpload'] = true; // optional
$fb = new Facebook($config);
$params = array(
// this is the access token for Fan Page
"access_token" => "I create this via the graph api (select App and click get token), I select publish stream and photo_upload permissions.",
"message" => "test message",
"source" => "#" ."photo.png", // "#" .
);
try {
// **** is Facebook id of Fan page
$ret = $fb->api('/****/photos', 'POST', $params);
echo 'Photo successfully uploaded to Facebook Album';
} catch(Exception $e) {
echo $e->getMessage();
}
the picture keeps going to MY wall (logged in user) and not the fan page, is that because im getting a token for the currently logged in user (me) instead of the fan page? and if so how do i generate a token for the fan page whilst logged in as the developer? (is it by putting the fan page id into the Get bar?)
Apologies for the noob questions but the facebook documentation sucks (until u understand the core functionality of course). Most tutorials work once u know how to use the graph API - none ive looked actually EXPLAIN how to use the graph to generate correct tokens, etc.
\POST /<ID>/photos — this will post on the <ID>'s wall only, so please double-check the <ID> that you are using.
The access token will depict that on behalf of whom the photo would be posted on the <ID>'s wall. If you use the user access token, the photo will be published on behalf of the user and if page access token is used, it will be published on the page's behalf itself.
You can get the page access token of your pages by-
\GET /me/accounts?fields=access_token
(permission required: manage_pages)
Demo
I have built a site with codeigniter and implemented facebook login for users. Everything is working great there. App is connected user tokens beig saved the whole nine yards. What I am having trouble doing is having the website itself NOT the logged in user post to the connected company facebook page on a user post completion. essentially the user posts a listing. the website then on submit of that posting posts to my facebook company page NOT the logged in users facebook wall. (i have that working already. Can i leave the website logged into Facebook to post to the wall while a user is logged on as well?
You will need to get the Appid, App secret and an access token. You can extend the access token so that it doesn't expire.
$graphUrl = 'https://graph.facebook.com/oauth/access_token?client_id='.APPID .'&client_secret='.APPSECRET.'&grant_type=fb_exchange_token&fb_exchange_token='.ACCESS_TOKEN;
$accessToken = #file_get_contents($graphUrl);
parse_str($accessToken); //get the access_token param in the string and would be named $access_token
if(!$access_token) $access_token = $accessToken; //if cannot be extended then just return the access token with 2 hours expiry
In order to post as your company page, you will need their page id.
Here is part of my script that I used to get all this working. Its not codeigniter, but you will be able to see how it works.
$config = array(
'appId' => APPID,
'secret' => APPSECRET,
);
$facebook = new Facebook($config);
$facebook->setAccessToken(ACCESS_TOKEN);
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
$page_id = '************'; //
$page_info = $facebook->api("/$page_id?fields=access_token");
if(!empty($page_info['access_token']) ) {
// do your code stuff
}
} catch etc etc
Hope this is helpful to you
I am new to PHP and facebook API'S
I am trying to get data from my ads account on faceobook using PHP
I just want to know how much $ every ads spent
First of all - I did not understand if I must have facebook app in order to get data from my personal ad account ?
I assumed yes so I created one now..,
I am geting the acess token like this :
require_once("facebook.php");
$config = array();
$config['appId'] = 'myapp_id';
$config['secret'] = 'myappsecret';
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config);
// Set a new app secret
$facebook->setApiSecret($config['secret']);
// If you do above, also set the app id
$facebook->setAppId( $config['appId']);
$access_token = $facebook->getAccessToken();
But when I am trying a get request like this:
https://graph.facebook.com/act_[my_account_number]/adgroups
I am getting a premisson exception that tell me
An access token is required to request his resource
But where do I put the access token ?
You need to add it at the end of the url as a url parameter:
"https://graph.facebook.com/act_[my_account_number]/adgroups" . "?access_token=" . $access_token
However, from the code I think you are getting an App Access Token, and you need a Page Access Token or a User Access Token to get the ads related to your Facebook Page.
Please refer to https://developers.facebook.com/docs/facebook-login/access-tokens/ for more information.
I am trying to use Facebook integration with Graph API
I registered with FaceBook, got my appID and Secret, downloaded the facebook-php-sdk-master and used this code:
require_once("facebook-php-sdk-master/src/facebook.php");
$config = array();
$config[‘appId’] = 'YOUR_APP_ID';
$config[‘secret’] = 'YOUR_APP_SECRET';
$config[‘fileUpload’] = false; // optional
$facebook = new Facebook($config);
$user = $facebook->getUser();
echo "user = ".$user;
Now when I try to use this code it always prints user = 0.
Have i Missed anything ?
ps: I have authorized the app too.
PPS: Could this because I am trying to test my code from localhost and facebook needs a website name for this to run ?
Thanks
You need to make sure that you have authorized the application. Just because you created the app does not mean the app knows who you are or can access your data.
Here is more info about logging in: https://developers.facebook.com/docs/technical-guides/login/
You first need to login and authorize the app.
My original point was to fetch the links of every photos of a facebook photo album, so I am trying to execute this FQL query:
select link from photo where aid=xxxxxxxxxxx
I want to execute it from php so I first tried to run the Facebook FQL sample from http://developers.facebook.com/docs/reference/fql/
But I can't figure out what is this line about:
$code = $_REQUEST["code"];
When is that $_REQUEST["code"] set ?
Any other simple ideas to fetch photo links of a given photo album?
The $_REQUEST variable referenced in the documentation pertains to the access token that the client (the website visitor) issues to your server once they grant permission for your to app to use their information. If you are accessing publicly accessible information you'll need an "app login" access token.
You should be using the php-sdk so getting that code isn't necessary because it handles all of that for you once you initialize a facebook instance with your app secret/id.
When I did something similar I did it this way:
require('src/facebook.php');
$config = array(
'appId' => 'YOURAPPID',
'secret' => 'YOURAPPSECRET',
'cookie' => true
);
$facebook = new Facebook($config);
$query = urlencode('select link from photo where aid=xxxxxxxxxxx');
try {
$fbData = $facebook->api("/fql?q={$query}");
} catch (FacebookApiException $e) {
$fbData = $e->getResult();
}
If you are accessing private information you'll need to follow the instructions on how to get the access token code. You can see an example of how to get that within the "example" folder of the sdk.