I want to fetch the count of Instagram followers but unable to fetch, i am implementing below code to fetch the number.
<?php
$username = 'shubhamtester14';
$response = #file_get_contents( "https://www.instagram.com/$username/?__a=1" );
if ( $response !== false ) {
$data = json_decode( $response, true );
if ( $data !== null ) {
$full_name = $data['graphql']['user']['full_name'];
$follower = $data['graphql']['user']['edge_followed_by']['count'];
echo "{$full_name} have {$follower} followers.";
}
} else {
echo 'Username not found.';
}
?>
Related
I was using this code until yesterday and it ran without any problems
But it does not work any more
Get post count from instagram api
<?php
$username = 'instagram';
$response = #file_get_contents( "https://www.instagram.com/$username/?__a=1" );
if ( $response !== false ) {
$data = json_decode( $response, true );
if ( $data !== null ) {
$full_name = $data['graphql']['user']['full_name'];
$follower = $data['graphql']['user']['edge_followed_by']['count'];
$follows = $data['graphql']['user']['edge_follow']['count'];
$posts = $data['graphql']['user']['edge_owner_to_timeline_media']['count'];
echo "<h2><a href='https://www.instagram.com/{$username}'>{$full_name}</a></h2>
<p><span>{$posts} posts</span> <span>{$follower} followers</span> <span>{$follows} following</span></p>";
}
} else {
echo 'Username not found.';
}
?>
I am trying to get the faceting results and I don't know how. there are no documentation for solr-php-client. In this example, print_r( $response->getRawResponse() ) does not include faceting. I am not sure weather faceting is not successfully requested or it is a matter of accessing the faceting data in the responce. Please also help me if there is any documentation available online for solr-php-client.
An other question is how to declare "user/password" if solr is protected when initiating the instance of solr-php-client
require_once( 'solr-php-client/Apache/Solr/Service.php' );
$solr = new Apache_Solr_Service( 'localhost', '8983', '/solr/products' );
if ( ! $solr->ping() ) {
echo 'Solr service not responding.';
exit;
}
$offset = 0;
$limit = 10;
$queries = array(
'name:iphone'
);
$additionalParameters = array(
'facet' => 'true',
'facet.field' => array(
'category'
)
);
foreach ( $queries as $query ) {
$response = $solr->search( $query, $offset, $limit );
if ( $response->getHttpStatus() == 200 ) {
print_r( $response->getRawResponse() );
if ( $response->response->numFound > 0 ) {
echo "$query <br />";
foreach ( $response->response->docs as $doc ) {
echo "$doc->id $doc->name <br />";
}
echo '<br />';
}else{
echo "zero results";
}
}
else {
echo $response->getHttpStatusMessage();
}
}
I missed to add $additionalParameters to the search arguements;
$response = $solr->search( $query, $offset, $limit,$additionalParameters );
im trying to modify a code, when i submit the form im getting this error "Creating default object from empty value". I make n echo statment in $request->isPost is not echoing. this my code below
public function addAction() {
$report = new Report();
$request = $this->getRequest ();
$validateOnly = $request->isXmlHttpRequest ();
if ($validateOnly)
$this->setNoRenderer ();
$userObj = new User ( );
$userRow = $userObj->createRow();
$status = ValidationContainer::instance ();
$userArray = $userRow->toArray ();
$userArray['acls'] = User::getACLs ( $user_id ); //set acls
$this->viewAssignEscaped ( 'user', $userArray );
$locations = Location::getAll();
$this->viewAssignEscaped('locations', $locations);
//var_dump($locations); exit;
if ($request->isPost()) {
self::fillFromArray ( $userRow, $details );
$userRow->is_blocked = 0;
if ($id = $userRow->save ()) {
in the provider_code table.
$this->insertPlainPassword($this->getSanParam('password'), $id);
$status->setStatusMessage ( 'The new user was created.' );
$this->saveAclCheckboxes ( $id );
} else {
$status->setStatusMessage ( 'The user could not be saved.' );
}
}
}
}
i have been trying to resolve it for weeks now.
}
I'm trying to save my data using php. This is how I tried:
<?php
session_start();
if(!isset($_SESSION["MemberID"])) header("Location:logout.php");
include '../config.php';
include '../momdb.php';
$page_title = "Customers";
$mode = "Save";
$db = 'db';
$showmessage = false;
$message = "";
if (isset ( $_POST ["btnSave"] )) {
$data = new table ();
$data->MomID = $_POST ["CustomerID"];
$data->CustomerName = $_POST ["CustomerName"];
$data->FromDate = string_to_date ( $_POST ["FromDate"] );
$data->ToDate = string_to_date ( $_POST ["ToDate"] );
$data->CreatedBy = $_SESSION["MemberID"];
$data->CreatedDatetime = date ( "Y-m-d H:i:s" );
$data->LastModifiedBy = $_SESSION["MemberID"];;
$data->LastModifiedDatetime = date ( "Y-m-d H:i:s" );
$rows = array ();
if (intval ( $data->CustomerID) > 0) {
$rows = $db::Update ( $data );
} else {
$rows = $db::Save ( $data );
}
if (intval ( $rows ["WebID"] ) > 0) {
$date = new DateTime ();
header ( "Location: customerlist.php?msg=yes&msgt=s&t=" . $date->getTimestamp () . "&mtext=Record saved successfully" );
} else {
$showmessage = true;
$message = $rows ["Message"];
}
} elseif (isset ( $_GET ["CustomerID"] )) {
$data = $db::GetByID ( $_GET ["CustomerID"] );
if ($data == false) {
$data = new table ();
$data->CustomerID = 0;
}
}
if ($data->CustomerID == "0")
$mode = "Save";
else
$mode = "Update";
?>
This code is for sending my values to the db page for saving them in the DB. I've used the PDO method. This is the first time I'm saving the record this way. That's why there is lots of confusion. The following code shows the Save() method, which I used to save the values to the DB.
public function Save(table $customer) {
$data = new DB ();
$stmt = $data->connection->prepare ( "CALL proc_CreateCustomer (:CustomerName, :FromDate,:ToDate,:CreatedBy, :CreatedDatetime, :LastModifiedBy, :LastModifiedDatetime)" );
$stmt->bindParam ( ':CustomerName', trim ($customer->CustomerName ));
$stmt->bindParam ( ':FromDate', $customer->FromDate );
$stmt->bindParam ( ':ToDate', $customer->ToDate);
$stmt->bindParam ( ':CreatedBy',$customer->CreatedBy );
$stmt->bindParam ( ':CreatedDatetime', $customer->CreatedDatetime );
$stmt->bindParam ( ':LastModifiedBy',$customer->LastModifiedBy );
$stmt->bindParam ( ':LastModifiedDatetime', $customer->LastModifiedDatetime );
$stmt->execute ();
$record = $stmt->fetch ( PDO::FETCH_OBJ );
if ($record == false) {
return array (
"WebID" => 0,
"Message" => $record->Message,
"AppID" => $customer->AndroidID
);
} else {
return array (
"WebID" => $record->CustomerID,
"Message" => $record->Message,
"AppID" => $customer->AndroidID
);
}
}
This is how I've tried. But, whenever I try to save the details, it shows: " Trying to get property of non-object in D:\Workspace\Application\momdb.php on line 39", ie it shows error in the line "Message" => $record->Message,"AppID" => $customer->AndroidID. I don't what's wrong with this. Can someone tell me what should I change so that it work fine?
if ($record == false) {
return array (
"WebID" => 0,
"Message" => $record->Message,
"AppID" => $customer->AndroidID
);
}
In this piece of code $record is false(y), so $record->Message doesn't exist.
I would like to be able to set a global username like <anythinghere>#domain3.com as a username value in the $usernames array (in code below). This is so that I can then go and redirect users based on domain, having already been "authenticated".
I will put example in code below.
Can i do something like $usernames = array("username#domain1.com", $X) where $X = <anything-so-long-as-not-blank>#domain3.com?
Full Code Below:
<?php
//VALIDATE USERS
$usernames = array("username#domain1.com", "username2#domain1.com", "username3#domain1.com", "username1#domain2.com", "username2#domain2.com", "username1#domain3.com");
$passwords = array("password1", "password2", "password3", "password4", "password5", "password6");
//REDIRECT SPECIFIC VALID USERS OR DOMAIN
function get_page($username) {
$username = strtolower($username);
switch ($username) {
case "username#domain1.com" : return "http://www.google.com";
case "username2#domain1.com" : return "http://www.yahoo.com";
case "username3#domain1.com" : return "http://www.stackoverflow.com";
case "username1#domain2.com" : return "http://www.serverfault.com";
}
return preg_match('/#domain3\.com$/',$username) ?
"http://www.backblaze.com" : "DefaultBackupPage.php";
}
$page = get_page($_POST['username']);
for($i=0;$i<count($usernames);$i++)
{
$logindata[$usernames[$i]]=$passwords[$i];
}
$found = 0;
for($i=0;$i<count($usernames);$i++)
{
if ($usernames[$i] == $_POST["username"])
{
$found = 1;
}
}
if ($found == 0)
{
header('Location: login.php?login_error=1');
exit;
}
if($logindata[$_POST["username"]]==$_POST["password"])
{
session_start();
$_SESSION["username"]=$_POST["username"];
header('Location: '.$page);
exit;
}
else
{
header('Location: login.php?login_error=1');
exit;
}
?>
#inhan Has already helped me like a champ. I am wondering if any one can get me over the line? Cheers!
Your code needed a clean-up first. There's a bunch of errors in it if you do a test run. It's also a bit hard to read IMO.
I've attached a working code sample below.
// Get users
$input_pwd = ( isset( $_POST["password"] ) ? $_POST["password"] : '' );
$input_user = ( isset( $_POST["username"] ) ? $_POST["username"] : '' );
// Your pseudo database here ;)
$usernames = array(
"username#domain1.com",
"username2#domain1.com",
"username3#domain1.com",
"username1#domain2.com",
"/[a-z][A-Z][0-9]#domain2\.com/", // use an emtpy password string for each of these
"/[^#]+#domain3\.com/" // entries if they don't need to authenticate
);
$passwords = array( "password1", "password2", "password3", "password4", "", "" );
// Create an array of username literals or patterns and corresponding redirection targets
$targets = array(
"username#domain1.com" => "http://www.google.com",
"username2#domain1.com" => "http://www.yahoo.com",
"username3#domain1.com" => "http://www.stackoverflow.com",
"username1#domain2.com" => "http://www.serverfault.com",
"/[a-z][A-Z][0-9]#domain2\.com/" => "http://target-for-aA1-usertypes.com",
"/[^#]+#domain3\.com/" => "http://target-for-all-domain3-users.com",
"/.+/" => "http://default-target-if-all-else-fails.com",
);
$logindata = array_combine( $usernames, $passwords );
if ( get_user_data( $input_user, $logindata ) === $input_pwd ) {
session_start();
$_SESSION["username"] = $input_user;
header('Location: ' . get_user_data( $input_user, $targets ) );
exit;
} else {
// Supplied username is invalid, or the corresponding password doesn't match
header('Location: login.php?login_error=1');
exit;
}
function get_user_data ( $user, array $data ) {
$retrieved = null;
foreach ( $data as $user_pattern => $value ) {
if (
( $user_pattern[0] == '/' and preg_match( $user_pattern, $user ) )
or ( $user_pattern[0] != '/' and $user_pattern === $user)
) {
$retrieved = $value;
break;
}
}
return $retrieved;
}