Instagram Profile Picture in Full-Resolution? - instagram

how do I get the profile picture of an instagram profile in full-res? (The old URL scheme stopped working today).
regex='profile_pic_url_hd":"([0-9a-zA-Z._-/:]*)",'
Is working for 320px pictures, but nothing else. The prefix to the 150x150 img is different, but the ID/ending of the url with jpg is the same.
Thanks

Okay guys I found a final solution:
Get the user_id of the account using this link https://www.instagram.com/{name}/?__a=1
Visit this JSON-API with the user_id above https://i.instagram.com/api/v1/users/{user_id}/info/
The full size profile picture link can be found in [hd_profile_pic_url_info][url]
Thats it! :)
[EDIT]
If step 1 doesn't work, my Php solution to get the user-id:
$name = "{username}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.instagram.com/$name/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($http=="200") {
$doc = new DOMDocument();
$doc->loadHTML($result);
$xpath = new DOMXPath($doc);
$js = $xpath->query('//body/script[#type="text/javascript"]')->item(0)->nodeValue;
$start = strpos($js, '{');
$end = strrpos($js, ';');
$json = substr($js, $start, $end - $start);
$data = json_decode($json, true);
$user_id = $data["entry_data"]["ProfilePage"][0]["graphql"]["user"]["id"];
}
I'm searching in the HTML document for user-id.

If you view the source html and run a simple find text search for logging_page_id, it will have profilePage_, then a number. That number is the user id.
e.g.:
logging_page_id":"profilePage_123456789
The user id is: 123456789

Related

Why can't acces to instagram recent media?

I am working with instagram api, to get top media and recent media, i don't have problems calling top media, but 2 days ago i implemented this and called 3 last recent media to my page,
today like 1 hour ago i only could see 1 of three last media i called and now after 1 hour can't see any of them when i print the array who contains recent media it says its empty i don't know why.
Checking calls from my application graphic it doesn't show a big traffic, so i think it's not the problem because i can see top media.
<?php
include 'define.php';
function makeApiCall($endpoint, $type, $params)
{
$ch = curl_init();
if ('POST' == $type) {
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_POST, 1);
} elseif ('GET' == $type) {
curl_setopt($ch, CURLOPT_URL, $endpoint . '?' . http_build_query($params));
}
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
$hashtag = 'sedapal';
$hashtagId = '17843308429009249';
$hashtagSearchEndpoingFormat = ENDPOINT_BASE . 'ig_hashtag_search?user_id={user-id}&q={hashtag-name}&fields=id,name';
$hashtagDataEndpointFormat = ENDPOINT_BASE . '{hashtag-id}?fields=id,name';
$hashtagTopMediaEndpointFormat = ENDPOINT_BASE . '{ig-hashtag-id}/top_media?user_id={user-id}&fields=id,caption,children,comments_count,like_count,media_type,media_url,permalink';
$hashtagRecentEndpointFormat = ENDPOINT_BASE . '{ig-hashtag-id}/recent_media?user_id={user-id}&fields=id,caption,children,comments_count,like_count,media_type,media_url,permalink';
$hashtagSearchEndpoint = ENDPOINT_BASE . 'ig_hashtag_search';
$hashtagSearchParams = array(
'user_id' => $instagramAccountId,
'fields' => 'id,name',
'q' => $hashtag,
'access_token' => $accessToken
);
$hashtagSearch = makeApiCall($hashtagSearchEndpoint, 'GET', $hashtagSearchParams);
/* To get hashtagID */
/* echo '<pre>';
print_r($hashtagSearch);
die(); */
$hashtagDataEndpoint = ENDPOINT_BASE . $hashtagId;
$hashtagDataParams = array(
'fields' => 'id,name',
'access_token' => $accessToken
);
$hashtagData = makeApiCall($hashtagDataEndpoint, 'GET', $hashtagDataParams);
$hashtagTopMediaEndpoint = ENDPOINT_BASE . $hashtagId . '/top_media';
$hashtagTopMediaParams = array(
'user_id' => $instagramAccountId,
'fields' => 'id,caption,children,comments_count,like_count,media_type,media_url,permalink',
'access_token' => $accessToken
);
$hashtagTopMedia = makeApiCall($hashtagTopMediaEndpoint, 'GET', $hashtagTopMediaParams);
$topPost = $hashtagTopMedia['data'][0];
$topPost1 = $hashtagTopMedia['data'][1];
$hashtagRecentEndpoint = ENDPOINT_BASE . $hashtagId . '/recent_media';
$hashtagRecentParams = array(
'user_id' => $instagramAccountId,
'fields' => 'id,caption,children,comments_count,like_count,media_type,media_url,permalink',
'access_token' => $accessToken
);
$hashtagRecent = makeApiCall($hashtagRecentEndpoint, 'GET', $hashtagRecentParams);
$recentPost = $hashtagRecent['data'][0];
/* $recentPost2 = $hashtagRecent['data'][1];
$recentPost3 = $hashtagRecent['data'][2]; */
?>
<p><?php echo json_encode($hashtagRecent['data']) ?></p>
That's because recent_media "Only returns media objects published within 24 hours of query execution", as said in the recent_media documentation.
The posts you couldn't see anymore were probably older than 24 hours the second time you fetched them.
top_posts will return posts no matter how old they are.
I struggled with this too and that was what happened to me.

How to allow text after a url

Im having trouble with my XAMPP website. I want to make a sort of profile like thing where users type (for example) https://howcoolitis.net/profile/useridhere
but that ends up just giving an error.
To be sincere, for the i have tried thing, There is not anything that i have tried apart from google searching similar like items, I don't really know what it is called to be honest, since i have never used it before but I want to use it.
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')
$url = "https";
else
$url = "http";
// Here append the common URL characters.
$url .= "://";
// Append the host(domain name, ip) to the URL.
$url .= $_SERVER['HTTP_HOST'];
// Append the requested resource location to the URL
$url .= $_SERVER['REQUEST_URI'];
// Print the link
$pos = strrpos($url, '/');
$search = $pos === false ? $url : substr($url, $pos + 1);
I was expecting for it to just give me the text after the url but it just gives a 404.

Joomla Exporting Or Downloading Reports To CSV

I have the following code in my inventory section when i run this code it save an excel file but the result showing the whole html file not my data.
<?php
$csv = NULL;
$arr = array("product_name","product_sku","product_in_stock","virtuemart_product_id","product_price_display","product_instock_value");
$csv = "Product Name, Product SKU, In Stock, Booked ordered products, Cost Price, Stock Value \n";
$c=0;
while(list($key,$value)=each($arr)){
$c++;
$cc=1;
foreach ($this->inventorylist as $key => $product){
$cc++;
$csv .= join(',',array($product->product_name.",".$product->product_sku.",".$product->product_in_stock.",".$product->virtuemart_product_id.",".$product->product_price_display.",".$product->product_instock_value))." \n";
}
}
JResponse::clearHeaders();
JResponse::setHeader('Content-Type', 'application/vnd.ms-excel', true);
JResponse::setHeader('Content-Disposition', 'csv; filename=inventory_report.csv; size='.strlen($csv), true);
JResponse::sendHeaders();
Any help will be appreciated.
Thanks
Khalique
Here's the brute force solution just to get you going:
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");
// Echo the csv content.
echo "foo,bar\n1,2";
// Close the application gracefully.
JFactory::getApplication()->close();
A slightly cleaner way without using views, but including &format=raw in the URL is:
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$doc->setMimeEncoding('application/vnd.ms-excel');
$app->setHeader(
'Content-disposition',
'attachment; filename="inventory_report.csv"',
true
);
echo "foo,bar\n1,2";
But the best way is to use a download view based on the raw document type. You can find an example of this in com_banners:
Controller: https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_banners/controllers/tracks.raw.php
View: https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_banners/views/tracks/view.raw.php
You might also gain some extra insight from this discussion https://groups.google.com/forum/#!topic/joomla-dev-general/dRa_39AGDBY

htaccess url rewrite but the ID changes

I wondering if it is possible to rewrite a url that might look something like this
www.example.com/item.php?id=1 to a www.example/item.php without the `?id=1`
Please note that 1 is for the product id so it might change to 2 or any number depending on what product the user choose
My current htaccess
My current .htaccess looks like this:
RewriteEngine on
RewriteBase /
RewriteRule ^item/(.*)$ test/main/pages/account/$1 [L] // **the item.php file is in the item folder**
ErrorDocument 404 /test/main/pages/general/index.php
Options -Indexes
AuthName "main"
I did it like
<?php
include('global.php'); ///database connection
function create_guid()
{
$microTime = microtime();
list($a_dec, $a_sec) = explode(" ", $microTime);
$dec_hex = dechex($a_dec* 1000000);
$sec_hex = dechex($a_sec);
ensure_length($dec_hex, 5);
ensure_length($sec_hex, 6);
$guid = "";
$guid .= $dec_hex;
$guid .= create_guid_section(3);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= $sec_hex;
$guid .= create_guid_section(6);
return $guid;
}
$stmt = $conn->prepare("INSERT INTO `Product (`pid`, `Guid`, `price`) VALUES
(13, '".$guid."', 13)");
$stmt->execute();
?>
also i did it using PDO because am I not a big fan of mysql
Since your main motive here to keep people form guessing the id in url and since as pointed out by lucas william that the way you want it is not possible in .htaccess instead you can store the id of each product in the database as guid format(this format of id storage into database is used by sugarCRM) which is also a proper substitute to satisfy you required and you can use that id to uniquely identify you product table each records:
The functions to create guid is as follows:
function create_guid()
{
$microTime = microtime();
list($a_dec, $a_sec) = explode(" ", $microTime);
$dec_hex = dechex($a_dec* 1000000);
$sec_hex = dechex($a_sec);
ensure_length($dec_hex, 5);
ensure_length($sec_hex, 6);
$guid = "";
$guid .= $dec_hex;
$guid .= create_guid_section(3);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= $sec_hex;
$guid .= create_guid_section(6);
return $guid;
}
function create_guid_section($characters)
{
$return = "";
for($i=0; $i<$characters; $i++)
{
$return .= dechex(mt_rand(0,15));
}
return $return;
}
function ensure_length(&$string, $length)
{
$strlen = strlen($string);
if($strlen < $length)
{
$string = str_pad($string,$length,"0");
}
else if($strlen > $length)
{
$string = substr($string, 0, $length);
}
}
Now using the above function you can generate the id as:
$guid = create_guid(); //guid is of the format 79cb3604-e634-a142-d9cb-5113745b31e2 which you can see is quite impossible to guess.
Also I would sugest that you keep the auto increment field in your product table.
Because it always a good idea to maintain a auto incremented field in a table to uniquely identity the records.
I hope this can be of some help
Edit :
what you need to do is add a field in you database product table named "guid"
so say your current database product table structure has the following fields:
id, name, price //where id is the auto incremented
after adding the field guid it becomes
id, guid, name, price //where id is auto incremented field and guid uniquely identifies each row in the product table
and when you do the insert of the product data in the database product table you generate the guid using the above code and insert it. ie
for example
$sql = "Insert into product_table('guid','product_name',product_price) values('".$guid."','product1','59.00');
so an example data in your product table will look like this:
1, 79cb3604-e634-a142-d9cb-5113745b31e2, product1, 59.00
Now in the product.php page with url say
yoursite.com/product.php?guid=79cb3604-e634-a142-d9cb-5113745b31e2
instead of using the url
yoursite.com/product.php?id=1
you can easily query the data from the database product table in relation to "guid" which of course also uniquely identifies each row in your product table in the database there by elimiting the risk of user guessing your id in url of the webpage.
I hope this gives you an idea of what i am trying to explain.
Using .htaccess, rewrite "www.example.com/item.php?id=1" to "www.example/item.php" is not possible because, how can we know, with an url like "www.example/item.php", if the product id is 1 or 2 ? It's impossible. So, with .htaccess, it's not possible.
However, you can cheat and use, simply, PHP and session variables, to do this rewriting, even if it's not a good solution. So, let your links under their current shape, with the get id parameter, and just add in your item.php file, a condition that will save the id value in a session variable and redirect to item.php if the id parameter is not empty.

Webforms in excel instead of e-mail

A client of mine asked me if i can find a solution for this problem.
His website (still a WIP) http://welkommagazine.nl/luuk/ has a form. The form obviously uses a sendmail script to send the form to e-mail. From thereon he manually copy/pastes all the submissions to excel.
What he wants is that the forms online automaticcaly are added to an excel document to save him a lot of work.
Now i am not a programmer, but a designer.. I think this can be done, but i have absolutely no clue how. I googled alot for it and the only thing i found was a dreamweaverplugin.
Is there a way to do this, if so, how?
Not a programmer's response, but...
I think an easy solution is to use Google docs. You can set-up a Google Spreadsheet and associate a form to it. Whenever a user fills the form , his data is added to the spreadsheet.
Your client may download that anytime.
There are some other providers on the market, some free, some not. E.g: wufoo.com
Found the answer myself. I wrote a PHP code snippet which actually stores the fields comma seperated in a CSV file and sends an email to a desired adress with the filled in fields.
if(isset($_POST['Submit'])){
$pakket = $_POST['pakket'];
$extragidsen = $_POST['extragidsen'];
$naambedrijf = $_POST['naambedrijf'];
$err = '';
if(trim($pakket)==''){
$err .= '-Please enter a name';
}
if(empty($extragidsen)){
$err .= '-Please enter an email address';
}
if(strlen($naambedrijf)==0){
$err .= '-Please enter a comment';
}
if($err!=''){
echo $err;
}
else{
$filename = 'file.csv';
$somecontent = $pakket . ',' . $extragidsen . ',' . $naambedrijf . "\n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
//--------------------------Set these paramaters--------------------------
// Subject of email sent to you.
$subject = 'Inschrijving welkom';
// Your email address. This is where the form information will be sent.
$emailadd = 'luuk#luukratief.com';
// Where to redirect after form is processed.
$url = 'http://www.google.com';
// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';
// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i ';
fclose($handle);
} else {
echo "The file $filename is not writable";
}
}
}
Maybe the code aint that clean as it can be, but eh it works.
Feel free to clean up the code if you want to :)
I guessed I would answer this myself for the community...
BTW u need to set "write" rights to "file.csv"
cheers

Resources