I can use the API to post to my facebook following the example at Simple example to post to a Facebook fan page via PHP?, as below
$data['picture'] = $image_URL;
$data['link'] = $link_URL;
$data['message'] = $message_TEXT;
$data['caption'] = $caption_TEXT;
$data['description'] = $description_TEXT;
$data['access_token'] = $page_access_token;
$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';
try{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);
}catch (Exception $e) {
echo 'ERROR '.$e.' in CURL for Facebook posting';
}
Is it possible to do something similar to share a post, if we know the URL of the post (e.g. https://www.facebook.com/TED/posts/10159368542595652)
Related
Please Guide me How to integrate ngenius-payment gateway to laravel app
Their documentation not enough to integrate with laravel.
i am planing to choose with making payments from their websites, and return back to us with a return URL.
Below php code i got from their documentation. but confused to integrate in laravel.
<?php
$postData = new StdClass();
$postData->action = "SALE";
$postData->amount = new StdClass();
$postData->amount->currencyCode = "AED";
$postData->amount->value = 100;
$outlet = "my-oulet-id";
$token = token_key(); //to ken generatig
$json = json_encode($postData);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api-gateway-uat.ngenius-
payments.com/transactions/outlets/".$outlet."/orders');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer ".$token,
"Content-Type: application/vnd.ni-payment.v2+json",
"Accept: application/vnd.ni-payment.v2+json"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$output = json_decode(curl_exec($ch));
$order_reference = $output->reference;
$order_paypage_url = $output->_links->payment->href;
curl_close ($ch);
function token_key(){
$apikey = "api-key"; // enter your API key here
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://identity-uat.ngenius-
payments.com/auth/realms/ni/protocol/openid-connect/token");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Basic ".$apikey,
"Content-Type: application/x-www-form-urlencoded"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query(array('grant_type' =>
'client_credentials')));
$output = json_decode(curl_exec($ch));
$access_token = $output->access_token;
return $access_token;
}
?>
****Below Code May Help You .. It works for me Up to their payment window****
public function make_payment(){
$outletRef = "your-outlet-id"; // set your outlet reference/ID value here (example only)
$apikey = "your-application-key"; // set your service account API key (example only)
$idServiceURL = "https://identity-uat.ngenius-payments.com/auth/realms/ni/protocol/openid-connect/token"; // set the identity service URL (example only)
$txnServiceURL = "https://api-gateway-uat.ngenius-payments.com/transactions/outlets/".$outletRef."/orders"; // set the transaction service URL (example only)
$tokenHeaders = array("Authorization: Basic ".$apikey, "Content-Type: application/x-www-form-urlencoded");
$tokenResponse = invokeCurlRequest("POST", $idServiceURL, $tokenHeaders, http_build_query(array('grant_type' => 'client_credentials')));
$tokenResponse = json_decode($tokenResponse);
$access_token = $tokenResponse->access_token;
$order = new StdClass();
$order->action = "AUTH"; // Transaction mode ("AUTH" = authorize only, no automatic settle/capture, "SALE" = authorize + automatic settle/capture)
$order->amount->currencyCode = "AED"; // Payment currency ('AED' only for now)
$order->amount->value = 01*100; // Minor units (1000 = 10.00 AED)
$order->language = "en"; // Payment page language ('en' or 'ar' only)
$order->merchantOrderReference = time(); // Payment page language ('en' or 'ar' only)
//$order->merchantAttributes->redirectUrl = "http://premizer.com/test/pp.php"; // A redirect URL to a page on your site to return the customer to
//$order->merchantAttributes->redirectUrl = "http://192.168.0.111:8080/n-genius/pp.php"; // A redirect URL to a page on your site to return the customer to
$order->merchantAttributes->redirectUrl = "your page url wich u want to redirect after payment success";
// A redirect URL to a page on your site to return the customer to
//$order->merchantAttributes->redirectUrl = "http:// 192.168.0.111:8080/n-genius/pp.php"; // A redirect URL to a page on your site to return the customer to
$order = json_encode($order);
$orderCreateHeaders = array("Authorization: Bearer ".$access_token, "Content-Type: application/vnd.ni-payment.v2+json", "Accept: application/vnd.ni-payment.v2+json");
$orderCreateResponse = invokeCurlRequest("POST", $txnServiceURL, $orderCreateHeaders, $order);
$orderCreateResponse = json_decode($orderCreateResponse);
$paymentLink = $orderCreateResponse->_links->payment->href; // the link to the payment page for redirection (either full-page redirect or iframe)
$orderReference = $orderCreateResponse->reference; // the reference to the order, which you should store in your records for future interaction with this order
header("Location: ".$paymentLink); // execute redirect
//die();
function invokeCurlRequest($type, $url, $headers, $post) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($type == "POST") {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$server_output = curl_exec ($ch);
// print_r($server_output);
// exit();
curl_close ($ch);
return $server_output;
}
}
Email them to get a valid test card details .. and check . all the very best .yo you
My request functions from PUBG official API
<?php
function getProfile($profile, $div){
$pubgapikey = 'xxxxxxxxxxxxx';
$id = getID($profile);
$url = "https://api.pubg.com/shards/pc-na/players/$id/seasons/$div";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $pubgapikey, 'Accept: application/vnd.api+json'));
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
$json = json_decode($result, true);
if($json["data"]["type"] == "playerSeason"){
return $json["data"]["attributes"];
}else {
return false;
}
}
function getID($name){
$pubgapikey = 'xxxxxxxxxxxxxxxxxxx';
$url = "https://api.pubg.com/shards/pc-na/players?filter[playerNames]=$name";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $pubgapikey, 'Accept: application/vnd.api+json'));
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
$json = json_decode($result, true);
return $json["data"][0]["id"];
}
So That's my function for requesting the data. I'll include the ways I call this.
// My index.php file (All requests go through here)
$page = explode("/", trim($_SERVER["REQUEST_URI"], "/"));
switch($page[0]){
case "profile":
require("controllers/search_controller.php");
$data = getProfile($page[1], "division.bro.official.2018-09");
if($data != false){
include("pages/profile.php");
}else{
include("pages/home.php");
echo '<script> document.getElementById("error").innerHTML = "Cannot find user. Remember To Be Capital Sensitive!"; </script>';
}
break;
}
I know that I'm using a really dumb way to include pages and what not but I don't wanna use or build my own php framework atm and this works just fine for what I'm doing
// Here is my php for calling the function
<?php
if (isset($_POST['username'])) {
$user = $_POST['username'];
if($user != ""){
header("Location: http://www.statstreak.us/profile/$user");
die();
}
}
?>
That's pretty much it. The form is just a basic html form.
For some reason this keeps using up my 25 requests/minute that I got from PUBG which is annoying as I can't find a reason why it would use up more than 2 requests per user
I was using CURL to publish on Facebook page but now it's not working anymore.
I need to publish on Facebook page using GraghAPI and CURL from my website to my pages.
This was code used before it was working for about 4 months ago but now not working:
$page_access_token = 'PAGE_ACCESS_TOKEN';
$page_id = 'PAGE_ID';
$data['picture'] = $news_image;
$data['link'] = $url_link;
$data['message'] = $title;
$data['caption'] = $title;
$data['description'] = $disc;
$data['access_token'] = $page_access_token;
$post_url = 'https://graph.facebook.com/' . $page_id . '/feed';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
How to publish to Facebook page without using Facebook App as it need a lot of verification to make an app.
My PHP code (free.php) on http://techmentry.com/free.php is
<?php
{
//Variables to POST
$access_token = "b34480a685e7d638d9ee3e53cXXXXX";
$message = "hi";
$send_to = "existing_contacts";
//Initialize CURL data to send via POST to the API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://freesmsgateway.com/api_send");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
array('access_token' => $access_token,
'message' => urlencode('hi'),
'send_to' => $send_to,)
);
//Execute CURL command and return into variable $result
$result = curl_exec($ch);
//Do stuff
echo "$result";
}
?>
I am getting this error: THE MESSAGE WAS BLANK
This error means: "The message field was blank or was not properly URL encoded" (as told by my SMS gateway). But as you can see that my message field isn't blank.
I believe you can't send an array to CURLOPT_POSTFIELDS, you would need to replace the line with the following
curl_setopt($ch, CURLOPT_POSTFIELDS, "access_token=".$accesstoken."&message=".urlencode('hi')."&send_to=".$send_to);
I hope this solves it
Use http_build_query():
<?php
{
$postdata = array();
//Variables to POST
$postdata['access_token'] = "b34480a685e7d638d9ee3e53cXXXXX";
$postdata['message'] = "hi";
$postdata['send_to'] = "existing_contacts";
//Initialize CURL data to send via POST to the API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://freesmsgateway.com/api_send");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postdata) );
//Execute CURL command and return into variable $result
$result = curl_exec($ch);
//Do stuff
echo "$result";
}
?>
having a bit of an issue with the twitter API. When I send something to https://api.twitter.com/1/statuses/update.json, the tweet (status update) does get sent, however, I do not get a response from twitter. When I send requests to any of the other api urls they work as expected and do return a response. Please see code below...
function postStatus($oauthToken,$status) {
//Create sig base string
$tokenddata = array('oauth_token'=>$oauthToken['oauth_token'],'oauth_token_secret'=>$oauthToken['oauth_token_secret']);
$status = rawurlencode($status);
$baseurl = $this->baseurl . "statuses/update.json";
$url = "{$baseurl}?status={$status}";
$authHeader = get_auth_header($url, $this->_consumer['key'], $this->_consumer['secret'],
$tokenddata, 'POST', $this->_consumer['algorithm']);
$postfields = "status={$status}";
$response = $this->_connect($url,$authHeader,$postfields,'POST');
return json_decode($response);
}
private function _connect($url, $auth, $postfields=null, $method='GET') {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($auth));
if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, TRUE);
if (!empty($postfields)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
}
}
$curl_info = curl_getinfo($ch);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
And as I said before, the other requests that I am using are 'GET' requests and use the code below...
function getFromTwitter($url, $oauthToken, $params=null) {
$tokenddata = array('oauth_token'=>$oauthToken['oauth_token'],'oauth_token_secret'=>$oauthToken['oauth_token_secret']);
$baseurl = $this->baseurl . $url;
if(!empty($params)) {
$fullurl = $baseurl . "?" . build_http_query($params);
$postfields = build_http_query($params);
$authHeader = get_auth_header($fullurl, $this->_consumer['key'], $this->_consumer['secret'],
$tokenddata, 'GET', $this->_consumer['algorithm']);
} else {
$authHeader = get_auth_header($baseurl, $this->_consumer['key'], $this->_consumer['secret'],
$tokenddata, 'GET', $this->_consumer['algorithm']);
}
if(!empty($postfields)) {
$response = $this->_connect($fullurl,$authHeader);
} else {
$response = $this->_connect($baseurl,$authHeader);
}
return json_decode($response);
}
Thanks for all of the help!
-SM
Implementing code for social networks on your own can be a pain (in my opinion)
It would be easier for you to use twitter-async (https://github.com/jmathai/twitter-async)
I have added it before to my CI as a helper function then used it as is.
It was easy to use & well documented.