OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
facebook
/
new_folder
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
10/14/2024 07:24:26 AM
rwxr-xr-x
📄
accessTest.php
657 bytes
10/10/2024 10:19:33 AM
rw-r--r--
📄
composer-setup.php
57.07 KB
10/10/2024 10:19:33 AM
rw-r--r--
📄
composer.json
64 bytes
10/10/2024 10:19:33 AM
rw-r--r--
📄
composer.lock
2.81 KB
10/10/2024 10:19:33 AM
rw-r--r--
📄
composer.phar
2.86 MB
10/10/2024 10:19:36 AM
rw-r--r--
📄
configuration.txt
79 bytes
10/10/2024 10:19:34 AM
rw-r--r--
📄
credential.json
556 bytes
10/10/2024 10:19:36 AM
rw-r--r--
📄
function.php
7.44 KB
10/10/2024 10:19:36 AM
rw-r--r--
📄
get_facebook_access_token.php
1.94 KB
10/10/2024 10:19:36 AM
rw-r--r--
📄
index.php
426 bytes
10/10/2024 10:19:37 AM
rw-r--r--
📄
permissionTest.php
1.31 KB
10/10/2024 10:19:37 AM
rw-r--r--
📄
postTest.php
1.29 KB
10/10/2024 10:19:37 AM
rw-r--r--
📄
post_to_page.php
2.29 KB
10/10/2024 10:19:37 AM
rw-r--r--
📄
share_facebook.php
1.66 KB
10/10/2024 10:19:37 AM
rw-r--r--
Editing: function.php
Close
<? function facebook_login_consent($credentials) { // Ensure 'app_id', 'scope', and 'redirect_uri' are provided in $credentials if (!isset($credentials['app_id'], $credentials['scope'])) { throw new InvalidArgumentException('Missing required credentials.'); } // Build the login URL $loginUrl = 'https://www.facebook.com/v20.0/dialog/oauth?' . http_build_query([ 'client_id' => $credentials['app_id'], 'redirect_uri' => 'https://knoblycream.com/testing/share_facebook.php', 'scope' => $credentials['scope'], 'response_type' => 'code' ]); return $loginUrl; } function facebook_generate_short_live_code($credentials) { $redirectUri = 'https://knoblycream.com/testing/share_facebook.php'; // Ensure this URL matches the one registered with Facebook // Ensure 'app_id', 'appSecret', and 'redirect_uri' are provided in $credentials if (!isset($credentials['app_id'], $credentials['appSecret'])) { throw new InvalidArgumentException('Missing required credentials.'); } // Check if 'code' is present in the query parameters if (!isset($_GET['code'])) { throw new InvalidArgumentException('Authorization code is missing.'); } // Exchange the code for a short-lived access token $tokenUrl = 'https://graph.facebook.com/v20.0/oauth/access_token?' . http_build_query([ 'client_id' => $credentials['app_id'], 'redirect_uri' => $redirectUri, 'client_secret' => $credentials['appSecret'], 'code' => $_GET['code'] ]); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $tokenUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); // Check if the cURL request was successful if (curl_errno($ch)) { curl_close($ch); throw new RuntimeException('cURL error: ' . curl_error($ch)); } curl_close($ch); $responseData = json_decode($response, true); // Check if the response contains the access token if (isset($responseData['access_token'])) { return $responseData['access_token']; } else { // Provide a more detailed error message throw new RuntimeException('Error obtaining short-lived token: ' . (isset($responseData['error']['message']) ? $responseData['error']['message'] : 'Unknown error')); } } function facebook_generate_page_tokens($shortLivedToken) { // Get Page Access Token Using User Access Token $pageTokenUrl = 'https://graph.facebook.com/v20.0/me/accounts?' . http_build_query([ 'access_token' => $shortLivedToken ]); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $pageTokenUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if (curl_errno($ch)) { curl_close($ch); throw new RuntimeException('cURL error: ' . curl_error($ch)); } curl_close($ch); $data = json_decode($response, true); // Check for errors if (isset($data['error'])) { throw new RuntimeException('Error: ' . $data['error']['message']); } return $data['data']; // Returns an array of pages and their respective access tokens } function facebook_generate_long_live_token($pageToken) { // Load credentials from the JSON file $credentials = json_decode(file_get_contents('credential.json'), true); if (!$credentials || !isset($credentials['app_id'], $credentials['appSecret'])) { throw new RuntimeException('Invalid or missing credentials in credential.json'); } // Exchange the short-lived page token for a long-lived token $longLivedTokenUrl = 'https://graph.facebook.com/v20.0/oauth/access_token?' . http_build_query([ 'grant_type' => 'fb_exchange_token', 'client_id' => $credentials['app_id'], 'client_secret' => $credentials['appSecret'], 'fb_exchange_token' => $pageToken, ]); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $longLivedTokenUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if (curl_errno($ch)) { curl_close($ch); throw new RuntimeException('cURL error: ' . curl_error($ch)); } curl_close($ch); $longLivedResponseData = json_decode($response, true); if (isset($longLivedResponseData['access_token'])) { $longLivedToken = $longLivedResponseData['access_token']; echo 'Long-Lived Access Token: ' . $longLivedToken . '<br>'; // Store the long-lived token back into the credentials JSON file $credentials['longLivedToken'] = $longLivedToken; file_put_contents('credential.json', json_encode($credentials, JSON_PRETTY_PRINT)); return $longLivedToken; } else { throw new RuntimeException('Error exchanging short-lived token for long-lived token: ' . $longLivedResponseData['error']['message']); } } function facebook_access_test($accessToken) { $url = 'https://graph.facebook.com/v20.0/me?fields=id,name&access_token=' . urlencode($accessToken); // Initialize cURL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Execute the request $response = curl_exec($ch); // Check if there was an error with cURL if (curl_errno($ch)) { curl_close($ch); throw new RuntimeException('cURL error: ' . curl_error($ch)); } curl_close($ch); // Decode the response $user = json_decode($response, true); // Check if there was an error in the API response if (isset($user['error'])) { throw new RuntimeException('Error: ' . $user['error']['message']); } // Return the user data as an array return [ 'id' => $user['id'], 'name' => $user['name'] ]; } function facebook_post_to_page($message, $link) { // Load credentials from the JSON file $credentials = json_decode(file_get_contents('credential.json'), true); if (!$credentials || !isset($credentials['longLivedToken'])) { throw new RuntimeException('Invalid or missing credentials in credential.json'); } $pageAccessToken = $credentials['longLivedToken']; // This should be the page access token $postUrl = 'https://graph.facebook.com/v20.0/me/feed'; // Data to send $postData = [ 'link' => $link, 'message' => $message, 'access_token' => $pageAccessToken, ]; // Initialize cURL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $postUrl); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Execute request $response = curl_exec($ch); // Check if there was an error with cURL if (curl_errno($ch)) { curl_close($ch); throw new RuntimeException('cURL error: ' . curl_error($ch)); } curl_close($ch); // Decode the response $responseData = json_decode($response, true); // Check if there was an error in the API response if (isset($responseData['error'])) { throw new RuntimeException('Error: ' . $responseData['error']['message']); } // Return success response return [ 'success' => true, 'message' => 'Message posted successfully!', 'response' => $responseData ]; }