MediaWiki API - Using new line for bullet points - php

I'm having trouble trying to do bullet points using the MediaWiki API, I can't work out how to get it to do the new line, everything ends up on the same line.
I've tried using
$maps[] = "* " . $mapName . "<br/>";
$maps[] = "* " . $mapName . "\n";
$maps[] = "* " . $mapName . "\r\n";
None of which work
I'm updating the wiki using
$endPoint = "URL";
$params4 = [
"action" => "edit",
"title" => $title,
"text" => $content,
"token" => $csrf_Token,
"format" => "json"
];
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $endPoint );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $params4 ) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, "cookie.txt" );
curl_setopt( $ch, CURLOPT_COOKIEFILE, "cookie.txt" );
$output = curl_exec( $ch );
curl_close( $ch );

Got it working using
$maps[] = "* [[" . $mapName . "]]<br/>%0D%0A";

Related

Need help on Facebook API how to get data from array with multiple fields

$endpointFormat = ENDPOINT_BASE . '{page-id}?fields=about,bio,description,new_like_count,talking_about_count,category,fan_count,link,name,rating_count,website,whatsapp_number,followers_count,country_page_likes,were_here_count,location&access_token={access-token}';
$statsAccountEndpoint = ENDPOINT_BASE . $pageId;
$statParams = array(
array ('fields' => 'about','bio','description','new_like_count', 'talking_about_count','category', 'fan_count', 'link','name','rating_count','website','whatsapp_number','followers_count','country_page_likes','were_here_count','location'),
'access_token' => $singleRow['fbaccesstoken']
);
// add params to endpoint
$statsAccountEndpoint .= '?' . http_build_query( $statParams );
// setup curl
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $statsAccountEndpoint );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
// make call and get response
$response = curl_exec( $ch );
curl_close( $ch );
$responseArray = json_decode( $response, true );
Printing out the statParams
Printing out responseArray which only shows the name and page id
Just wanting to get the stats of the page im linking, tried with only 1 field variable before and it showed fine. Thanks for your time!
$statParams = array(
'fields' => 'about,bio,description,new_like_count,talking_about_count,category,fan_count,link,name,rating_count,website,whatsapp_number,followers_count,country_page_likes,were_here_count,location',
);
just had to make it so that everything is in one big '' instead of separate.

eBay api search item

I want to get items by keyword search.
<?php
error_reporting(E_ALL);
require_once("includes/config.php");
// Construct the HTTP GET call
$apicall = "https://api.ebay.com/buy/browse/v1/item_summary/search?"; //
URL to call
$apicall .= "q=GTR"; //search keyword
$apicall .= "limit=3";
// Create headers to send with CURL request.
$headers = array
(
'X-EBAY-API-APP-ID: ' . $sapp_id,
'X-EBAY-API-DEV-NAME: ' . $dev_id,
'X-EBAY-API-CERT-NAME: ' . $cert_id,
'X-EBAY-C-ENDUSERCTX: 5337984774'
);
// Send request to eBay and load response in $response
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL,
"https://api.ebay.com/buy/browse/v1/item_summary/search?");
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $apicall);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
// Load the call and capture the document returned by eBay API
$resp = $response;
// Output response
echo("<pre>");
print_r($resp);
//To retrieve specific values of the array in PHP, you will need to use
object operator
// $value = $resp->Item->ConvertedCurrentPrice;
// $value = $resp->Item->ConvertedCurrentPrice;
// print $xml->Product->Title;
echo("</pre>");
?>
i got this error when i run.
{
"errors": [
{
"errorId": 3001,
"domain": "ROUTING",
"category": "REQUEST",
"message": "Request Rejected",
"longMessage": "The Request has errors. For help, see the documentation for this API."
}
]
}
Since i am beginner i don't know what to do.
i tried xml request method and it's work fine but i want to do it with REST API method.
i follow this docs - Official eBay search api documentation
i like to know why i am getting this error and what's the correct way to achieve this search query ?
Not tested as I don't have an eBay developer account but perhaps the following might help. The code below will issue a GET request with the querystring as part of the url as the documentation suggests
<?php
error_reporting( E_ALL );
require_once("includes/config.php");
/*
you can download from https://curl.haxx.se/docs/caextract.html
*/
$cacert='c:/wwwroot/cacert.pem'; # edit as appropriate to point to valid `cacert.pem` file
$verbose=true;
$endpoint = "https://api.ebay.com/buy/browse/v1/item_summary/search?";
$args=array(
'q' => 'GTR',
'limit' => 3
);
$url=sprintf( '%s%s', $endpoint, http_build_query( $args ) );
/*
for advanced debug information we create a stream
and output to that during the request. At the end
of the request the stream is processed and we can
view that data.
*/
if( $verbose )$vbh = fopen('php://temp', 'w+');
$headers = array(
'X-EBAY-API-APP-ID: ' . $sapp_id,
'X-EBAY-API-DEV-NAME: ' . $dev_id,
'X-EBAY-API-CERT-NAME: ' . $cert_id,
'X-EBAY-C-ENDUSERCTX: 5337984774'
);
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $url );
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $curl, CURLOPT_CAINFO, $cacert );
curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl, CURLOPT_USERAGENT, 'curl' );
if( $verbose ){
curl_setopt( $curl, CURLOPT_VERBOSE, true );
curl_setopt( $curl, CURLOPT_NOPROGRESS, true );
curl_setopt( $curl, CURLOPT_STDERR, $vbh ); # the stream object
}
/* make the request and get info */
$response = curl_exec( $curl );
$info=(object)curl_getinfo( $curl );
$errors=curl_error( $curl );
/* store the verbose debug info */
if( $verbose ){
rewind( $vbh );
$debug=stream_get_contents( $vbh );
fclose( $vbh );
}
curl_close( $curl );
if( $info->http_code==200 ){
printf( '<pre>%s</pre>', print_r( $response, 1 ) );
} else{
printf( '<pre>%s</pre>', print_r( $verbose ? $debug : $info ,1 ) );
printf( '<pre>%s</pre>', print_r( $errors, 1 ) );
}
?>

What is going wrong with this API?

I am coding a website for my friend whom plays Habbo Hotel which is a virtual game. He linked me to some API.
http://habboemotion.com/guide/habinfo & http://habboemotion.com/guide/habboapi
I have been using this code to show the data from the api.
<?php
$info = habbo( "Tyler", "com" );
if( $info ) {
foreach( $info->user AS $name ) {
echo $name->motto;
}
} else {
echo "Habbo not found";
}
?>
Why is nothing appearing? It just appears to be a blank screen.
As the previous person said, make sure to include your habbo() function.
I changed the habbo() function to remove gzip compression and gzinflate(). That seemed to fix the blank page issue. However it seems to take a few seconds to load the page and is on the slow side.
It would also appear that $user->motto isn't allowed. As such, I've replaced it with $friends->motto.
Hope this helps! I am still very new to APIs.
<?php
error_reporting(E_ALL); // Debugging
ini_set('display_errors', 1); // Debugging
function habbo( $name, $hotel ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "https://www.habbo." . $hotel . "/api/public/users" );
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Accept-Encoding: identity' ) ); // Changed to "identity"
curl_setopt( $ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
$response = curl_exec( $ch ); // Added
//$get = gzinflate( substr( curl_exec( $ch ), 10, -8 ) );
//preg_match( "/setCookie\((.*)\);/", $get, $get );
//$get = explode( ",", str_replace( array( "'", " " ), "", $get[1] ) );
//curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "Cookie:" . $get[0] . "=" . $get[1] ) );
curl_setopt( $ch, CURLOPT_URL, "http://www.habbo." . $hotel . "/api/public/users?name=" . $name );
$id = json_decode( curl_exec( $ch ) );
if( isset( $id ) && $id->profileVisible == 1 ) {
curl_setopt( $ch, CURLOPT_URL, "http://www.habbo." . $hotel . "/api/public/users/" . $id->uniqueId . "/profile" );
$info = json_decode( curl_exec( $ch ) );
} else
$info = false;
curl_close( $ch );
return $info;
}
Here is the function call:
$info = habbo( "Tyler", "com" );
if( $info ) {
foreach( $info->friends AS $friend ) {
echo $friend->motto . "<br />";
}
} else {
echo "habbo not found or homepage hidden";
}
?>

Invoke a php script as a new record inserted into db

I am just creating a web service for push notification. I Here is my code -
<?php
// gcm api KEY FOR PUSH NOTIFICATION
define( 'API_ACCESS_KEY', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456' );
// CONNECT DB
$dbhandle = mysql_connect("localhost", "admin", "admin") or die(mysql_error()) ;
$selected = mysql_select_db("bdname" ,$dbhandle) or die(mysql_error());
$query4=mysql_query("SELECT * FROM `table_name` ORDER BY id DESC LIMIT 0,1");
$row1=mysql_fetch_array($query4);
// static gcm registration id
$reg = 'APA91bF-A97EurJz7IlGFD85cBIWGPCJv7UhV1j19sp6nKEH-9He1GOZQ9ZPegqYmVw3q2OA-_XPpePQckr5o97s9wTTbzYjornXCOqcR3jmN1t1aHV8i4CfRZOWuBDXTixzA3JDnzleHVY3xCtHev8tG90ife05Pw';
$registrationIds = array($reg);
$title=$row1['title'];
$number=$row1['number'];
$id=$row1['id'];
$created_at=$row1['created_at'];
$mes1 = $id .',' . $title . ',' . $number .',' . $created_at;
$message = str_replace('""','',$mes1);
$mes = $message;
$message = array("price" => $mes);
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registrationIds,
'data' => $message,
);
$headers = array(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
echo $result;
//}
mysql_free_result($query4);
mysql_close($dbhandle);
?>
I just want if any new row inserted into table, this script will automatic invoke and send notification on given gcm registration id. How can i do this. Is there any php function to do this??
Please help.
Thanks in advance.
Please use this php method to send GCM notification
function sendNotification( $apiKey, $registrationIdsArray, $messageData )
{
$headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $apiKey);
$data = array(
'data' => $messageData,
'registration_ids' => $registrationIdsArray
);
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send" );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($data) );
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
Refer these links for detailed tuts on GCM implementation with php
http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/
http://distriqt.com/post/1273

Php script for push notfication returns nothing

I have this script for sending a push notification on my android app :
<?php
// Replace with real BROWSER API key from Google APIs
$apiKey = "AIzaSyAATjQOVDdOUiHra0H-EfxpobQcqOsdwqa";
// Replace with real client registration IDs. Put the correct registration id you are getting from app. If you are using eclipse check your logcat you will get it there.
$registrationIDs = array("APA91bEmxWS9bsXLsixaYQ6zuByM0SzFWe5DEKVLO68923hW3Mo2qB6bIH2LarP5WgzKasMtFAdVyy8YQuwv0YbrRNwdGFORh1wQvQ9uKBkC3jH6uXBYAQOv5xfzrsjYjqcQK8syikrQ6dq6oRrp9XUnimdj_4oBbw" );
// Message to be sent
$message = "Push working!";
// Set POST variables.
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message ) /*Make sure that message is the key you are using in GCMIntentService.java onMessage() -> extras.getString("message");*/
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
// Echo success or failure
echo $result;
?>
I never get any push notification on my phone. The thing is that actually i never get any output from the script like the echo $result; returns nothing.
Is this even possible?
Any ideas?
Solution
<?php
// Replace with real BROWSER API key from Google APIs
$apiKey = "AIzaSyAATjQOVDdOUiHra0H-EfxpobQcqOsdwqa";
// Replace with real client registration IDs. Put the correct registration id you are getting from app. If you are using eclipse check your logcat you will get it there.
$registrationIDs = array("APA91bEmxWS9bsXLsixaYQ6zuByM0SzFWe5DEKVLO68923hW3Mo2qB6bIH2LarP5WgzKasMtFAdVyy8YQuwv0YbrRNwdGFORh1wQvQ9uKBkC3jH6uXBYAQOv5xfzrsjYjqcQK8syikrQ6dq6oRrp9XUnimdj_4oBbw" );
// Message to be sent
$message = "Push working!";
// Set POST variables.
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message ) /*Make sure that message is the key you are using in GCMIntentService.java onMessage() -> extras.getString("message");*/
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
// Echo success or failure
echo $result;
?>
Now it works perfectly.
Found the error.
Replace line curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
with line curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
I corrected the code on the question so now it works.

Categories