samedi 18 avril 2015

Access facebook pages remotely without standard login process

I am trying to create an application that allows access to MY facebook page. I have registered the application with facebook and have the client id and application secret (easy part).


What i want to do (in the approximate order i wish to perform)




  1. Test if user is an admin of MY website. -> i handle this myself and has nothing to do with the facebook api application itself.




  2. If the user is not an admin. i want the public data of MY page displayed



    • items i want to be able to access are user's feeds, user's photos, user's friends, user's profile




  3. If the user is an admin the user will get added permissions (once again my website will handle the authorization of such user)




    • once a user has been authorized as admin i want to run additional queries to authorize them to post updates, add/delete posts and upload photos.




    • I dont want the admin users to be forced to login as a standard user. Instead i want them to be login in automatically-without any noticeable changes to the website such as redirects.




    • I have been using cURL as the medium between my website and facebook.




    • The problem i face is that without using facebooks standard login process (ie. the individual users have to login using their credentials) i yield no results. From their i cannot get any accessTokens as to edit the pages i need user access tokens.



      1. Once this background login is completed i can use it to authorize the access tokens and have the user act on behalf of the page itself. I DO NOT WANT THE USER TO ACT AS THEMSELVES. I WANT THE USER TO ACT ON BEHALF OF THE PAGE.




    • odvisiouly, i cannot give every user this capability and that is why i handle this on my website.






Currently i am using the following code(ive tried about two dozen different variations to try and get this working and i have nothing yet)



//SET DEFAULT APP VARS
public $cookie_file_path = '/var/www/html/cookie.txt';
public $appId = 'CLIENT ID';
public $appSecret = 'APP SECRET';
public $pageId = 'PAGE ID';
public $redirectUri = 'REDIRECT URL';
public $scopes = 'SCOPES';


//GET URL CODE
function getCode(){
try{
//TEST FOR SET VARS
if(!isset($this->appId) || !isset($this->redirectUri)){
throw new Exception ("You have not set the application credentials");
}

//MAKE URL
$this->url = 'http://ift.tt/1DV8LjM'.$this->appId;
$this->url.= '&redirect_uri='.$this->redirectUri;

header("Location:". $this->url);

}catch(Exception $e){
return $this->error($e);
}

}
function http //<--this is just my cURL function


This code uses a redirect back to the page that called it and then sets a session var so it doesnt loop.


However this code only works if the user themselves has already logged into facebook.


Aucun commentaire:

Enregistrer un commentaire