how to get different Instagram feeds? - wordpress

I build a instagram widget in my wordpress theme. And now I want to do a website demo, I want to display some ins feeds of famous instagram authors with my access token. But it seems that I can only display my own instagram feeds with my access token and user id. why? is ins change its API? I saw some author at themeforest can still display different instagram feed of famous ins authors. Could you teach me how to do that?

To the first question. Yes, Instagram restricted access
Every new app created on the Instagram Platform starts in Sandbox
mode. Apps in this mode can use any API endpoint but are restricted to
a limited number of users and media. This is great for developing and
testing your app.
To go Live and fully access Instagram content, you will need to submit
your application for review and approval. Once reviewed, you will only
be able to request users the Permission Scopes for which your app was
approved. Because of this, your application may not be able to use
some API endpoints unless the corresponding permissions were reviewed
and approved.
But you can get feeds making calls to web-version with ?__a=1 parameter. In this case you recieve json. You need to write some code:
$otherPage = 'nasa';
$profileUrl = "https://www.instagram.com/$otherPage/?__a=1";
$iterationUrl = $profileUrl;
$tryNext = true;
$limit = 100;
$found = 0;
while ($tryNext) {
$tryNext = false;
$response = file_get_contents($iterationUrl);
if ($response === false) {
break;
}
$data = json_decode($response, true);
if ($data === null) {
break;
}
$media = $data['user']['media'];
$found += count($media['nodes']);
var_dump($media['nodes']);
if ($media['page_info']['has_next_page'] && $found < $limit) {
$iterationUrl = $profileUrl . '&max_id=' . $media['page_info']['end_cursor'];
$tryNext = true;
}
}
If you need only 12 media from one feed, your code can be simplier (without while). In both cases use $media to save a feed in your storage, then display it on your pages.

Please go through the instagram feed wordpress plugin https://wordpress.org/plugins/evm-social-gallery/, For instagram feed for wordpress website.

Related

Fix Self referral issue in GA4 property

Our GA4 property in Google analytics is showing our own website as a referral source. Normaly, in ga3 property there is a filter where you can exclude sites like payment portals and such. In the new property this feature is not yet available.
We tried using the following script to workaround the problem
var ref = {{Referrer}};
// don't bother if there is no referrer
if (!ref) return ref;
var newref;
// place your external referrers here (domain names)
// adding 'foo.bar.com' matches 'www.foo.bar.com' too
var domains = [
// banks
'rabobank.nl', 'ing.nl', 'abnamro.nl', 'regiobank.nl', 'snsbank.nl',
'asnbank.nl', 'triodos.nl', 'vanlanschot.nl', 'knab.nl', 'bunq.com',
'frieslandbank.nl', 'snsreaal.nl', 'secure-ing.com',
// payment providers, cards, foreign banks
'mollie.nl', 'mollie.com', 'paypal.com', 'paypal.nl', 'adyen.com',
'multisafepay.com', 'visa.com', 'wlp-acs.com', 'belfius.be', 'payin3.nl',
'icscards.nl', 'arcot.com', 'securesuite.co.uk', 'hsbc.com.hk',
'cm-cic.com', 'pay.nl', 'redsys.es', 'tatrabanka.sk'
];
domains.forEach(function(x) {
// loop through domains,
if(ref.match(RegExp('^https?://([^.]+\.)?'+ x +'/')))
newref = x;
})
// return referrer, or the new one
return newref ?
'https://' + {{Page Hostname}} + '/excluded-referrer/' + newref
: ref
}
The script does not work though. Could you give me any new recommendation on how to solve this issue or tell me if the code might be wrong?
Thanks
Update: Google actually releases gradually a referral exclusion feature in GA4, which you can find here:https://support.google.com/analytics/answer/10327750?ck_subscriber_id=750579406
Thankfully this will help with this problem.

Remove user and all its posts

I need to use WordPress Rest API to delete a user and all its own (maybe custom) posts.
I tried to call <url_base>/wp/v2/users/<id> and I have to provide a further parameter ?reassign=USER_ID to reassign its posts to another user.
A silly solution should be adding a "garbage" user to the system and assign him all deleted posts. Then I can create a job to delete all posts. It seems a very stupid way to me.. :(
I just want to delete them. I can do it from WP admin panel... why I can't via Rest Api?
Thanks
EDIT
Passing "reassign" as an empty params (null is not accepted...) the API informs me that I'm not able to delete my own profile. I'm testing it as a subscriber (end user), but I need to be able to manage and delete my own data... Am I wrong?!
This is my solution... maybe not the best one, but it seems to work.
I added delete_users and remove_users capabilities to the Subscriber role (for my convenience).
My /DeleteUsers rest endpoint check for the user ID encrypted inside the JWT token that is sent in header and compare it with the user_id params. If they match, I can delete the user.
Now I just have to avoid that a user can access the WP Admin panel and make some mess!
This is the code:
function myDeleteProfile($data) {
require_once(ABSPATH.'wp-admin/includes/user.php');
$headers = getallheaders();
if(!isset($headers['Authorization']) || !$headers['Authorization']) {
return array('esito'=>'ko', 'descrizione'=>'Fail message!');
}
$jwt_parts = preg_split('/\./', $headers['Authorization']);
$jwt_decoded = json_decode(base64_decode($jwt_parts[1]));
$jwt_user = $jwt_decoded->data->user->id;
if( intval($data['user_id']) != intval($jwt_user) ) {
return array('esito'=>'ko', 'descrizione'=>'User cannot delete.');
}
else {
if( wp_delete_user($jwt_user,null) ){
return array('esito'=>'ok', 'descrizione'=>'Deleting...');
}
else {
return array('esito'=>'ko', 'descrizione'=>'Error.');
}
}
}

I am noticing double entry (cpc and organic) for the same user ? little confused

I'm noticing double entry in google analytics. I have multiple ocurrences where it looks like the user came from the CPC campaign (which always has a 0s session duration) but that very same user also has an entry for "organic" and all the activities are logged under that.
My site is not ranked organically for those keywords. Unless a so many users come to my site, leave, and google for my "brand name" on google and revisits, this doesn't make sense.
I'm a little confused. Here's the report:
preview from google analytics dashboard
Based on the additional information in your comment, that the sites is a Single Page Application (SPA), you are most likely facing the problem of 'Rogue Referral'.
If this is the case, what happens, is that you overwrite the location field in the Analytics hit, losing the original UTM parameters, whereas referral is still sent with the hit, so Analytics recognizes the second hit as a new traffic source. One of the solutions is to store the original page URL and send it as the location, while sending the actual visited URL in the page field.
A very good article on this topic with further tips, by Simo Ahava, is available for your help.
Also please note, that as you have mentioned, that the first hit shows 0 second time on page, you might need to check, whether the first visited page is sent twice. E.g. sending a hit on the traditional page load event, and sending a hit for the same page as a virtual page view.
I have come up with a solution to this problem in a Gatsby website (a SPA), by writing the main logic in the gatsby-browser.js file, inside the onRouteUpdate function.
You can use this solution in other contexts, but please note that the code needs to run at the first load of the page and at every route change.
If you want the solution to work in browsers that do not support URLSearchParams I think you can easily find a polyfill.
Function to retrieve the parameters
// return the whole parameters only if at least one of the desired parameters exists
const retrieveParams = () => {
let storedParams;
if ('URLSearchParams' in window) {
// Browser supports URLSearchParams
const url = new URL(window.location.href);
const params = new URLSearchParams(url.search);
const requestedParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'gclid'];
const hasRequestedParams = requestedParams.some((param) => {
// true if it exists
return !!params.get(param);
});
if (hasRequestedParams) {
storedParams = params;
}
}
return storedParams;
}
Create the full URL
// look at existing parameters (from previous page navigations) or retrieve new ones
const storedParams = window.storedParams || retrieveParams();
let storedParamsUrl;
if (storedParams) {
// update window value
window.storedParams = storedParams;
// create the url
const urlWithoutParams = document.location.protocol + '//' + document.location.hostname + document.location.pathname;
storedParamsUrl = `${urlWithoutParams}?${storedParams}`;
}
Send the value to analytics (using gtag)
// gtag
gtag('config', 'YOUR_GA_ID', {
// ... other parameters
page_location: storedParamsUrl ?? window.location.href
});
or
gtag('event', 'page_view', {
// ... other parameters
page_location: storedParamsUrl ?? window.location.href,
send_to: 'YOUR_GA_ID'
})

Can Google Analytics email me if (crashes and) exceptions occur?

Google Analytics is correctly reporting exceptions thrown by my Android app. And I can use Scheduled Emails to send this report to me. However, receiving a daily email when there isn't anything to report (i.e., the report tells me that zero exceptions occurred) is tedious. Thus, I'd like to receive emails only when there is something to report (i.e., the report tells me that one or more exceptions occurred). It seems that Custom Alerts can be used for this purpose. However, Custom Alerts do not appear to be compatible with Exceptions. This leads me to my question.
Can Custom Alerts be configured to provide email notification on exceptions?
Or, more generally,
Can Google Analytics be configured to provide email notification on exceptions?
Also, does this work for crashes too?
UPDATE (22 Nov 2015, 1 Dec 2015)
(Partial) answer. I provide an answer that enables a server (not Google Analytics) to be configured to provide email notification on exceptions, which is probably a sufficient solution for many.
(Almost an) answer. jakub-kriz has provided a detailed answer, but it does not work as-is. Building upon the answer, I was able to configure Google Analytics to email when no exceptions occur. This is the exact opposite of what is required. Unfortunately, I have been unable to get emails when one or more exceptions occur.
Alternate direction. jakub-kriz has proposed an alternative solution, whereby normal events are used, rather than exception events. I haven't tried this direction.
A complete solution has not yet been proposed.
It is possible, but not in a direct way, you have to hookup you analytics quite dirty.
1) Configuration in Analytics Admin
Create two filters in Admin -> View -> Filters -> Custom -> Advanced
Create filter that listens on hitType exception and set Event Category - Exception
Create filter that replicates Exception description into Event Action
2) Create custom Goal
Create two filters in Admin -> View -> Goals -> Custom -> Event
Event Category equals Exception
3) Create Custom Alert
Custom alert by Goal containg exception
Do not forget your email
Try this and let me know!
To get report on Mail Id there is no way to send directly from google analytics. We can send this error report handling it and send it to programmatically to mail id from our app.
A server (not Google Analytics) can be configured to provide email notification on exceptions, which is probably a sufficient solution for many.
First, you need a service account, which can be created https://console.developers.google.com/project/_/apiui/credential. You'll create a key file (MyAnalytics.p12).
Secondly, we configure our analytics client (MyAnalytics.php):
<?php
//You'll need to install google-api-php-client
//(https://github.com/google/google-api-php-client)
require_once 'Google/autoload.php';
class MyAnalytics
{
//When logged into Google Analytics you'll have a URL that looks
//something like https://www.google.com/analytics/web/?authuser=0#home/a00w11p22/
//Your profile id is everything after the p
const PROFILE_ID = '22';
//This is the service account email that you constructed in step 1
const SERVICE_ACCOUNT_EMAIL = 'blah#developer.gserviceaccount.com';
//This is the file that you constructed in step 1.
const KEY_FILE_LOCATION = 'MyAnalytics.p12';
private $client;
private $analytics;
private $cred;
public function __construct() {
$this->client = new Google_Client();
$this->analytics = new Google_Service_Analytics($this->client);
$key = file_get_contents(self::KEY_FILE_LOCATION);
$this->cred = new Google_Auth_AssertionCredentials(
self::SERVICE_ACCOUNT_EMAIL,
array(Google_Service_Analytics::ANALYTICS_READONLY),
$key
);
}
public function getAnalytics() {
$this->client->setAssertionCredentials($this->cred);
if($this->client->getAuth()->isAccessTokenExpired()) {
$this->client->getAuth()->refreshTokenWithAssertion($this->cred);
}
return $this->analytics;
}
}
?>
Thirdly, we query and report on exceptions (exceptions.php):
<?php
require_once 'MyAnalytics.php';
$myAnalytics = new MyAnalytics();
$analytics = $myAnalytics->getAnalytics();
$results = $analytics->data_ga->get(
'ga:' . MyAnalytics::PROFILE_ID,
'yesterday',
'today',
'ga:exceptions'
);
$a = $results->getTotalsForAllResults();
$count = $a['ga:exceptions'];
echo $count;
if (is_numeric($count) && $count > 0) {
//handle the exception, e.g., send an email
//(cf. https://stackoverflow.com/a/5335311/3664487)
}
?>
Fourth, configure cron to run exceptions.php (cf. https://stackoverflow.com/a/22358929/3664487).

How Can I Trigger An Email Notification To Purchaser in WP-Ecommerce Using WP-Ecommerce-Shopstyling When An Order Is Submitted?

I'm trying to trigger two emails during the check out process of WP-Ecommerce and have them styled using your awesome plugin.
Order Submitted - not sending anything to the buyer at the moment
Accepted Payment - working and styled using "wp-ecommerce-shopstyling"
Can you help me out with this? I would really love to be able to have an email sent to the buyer when they submit their order.
My client takes offline credit card payments, so I would like the buyer to know their order was sent (and is waiting for processing), and then the order was paid for and being created - the shop is a flower shop.
Currently the 'accepted payment' step works. But the submitted step, isn't sending anything. Any help would be awesome.
Cheers,
Fiona
The email trigger is part of the WP E-Commerce core functionality. The Shop-Styling plugin just adds a nice formatting to the existing mail.
Your customers receive an email when they submit their order and as soon as you change the payment status to "payment accepted". This is the intended behavior.
You can use a hook in your themes function.php:
add_action('wpsc_update_purchase_log_status', 'triggerStatusChangeMail', 9, 4 );
function triggerStatusChange($id, $status, $old_status, $purchase_log ) {
// WPSC_Purchase_Log::INCOMPLETE_SALE //= 1;
// const ORDER_RECEIVED = 2;
// const ACCEPTED_PAYMENT = 3;
// const JOB_DISPATCHED = 4;
// const CLOSED_ORDER = 5;
// const PAYMENT_DECLINED = 6;
// const REFUNDED = 7;
// const REFUND_PENDING = 8;
if ($status==2){
wp_mail(...);
}
}
You can use HTML code in your mail content and the Mail-Template will also be applied to your custom email automatically, but you cannot use any placeholders. If you want to add customer or order details in your mail you have to query all information from the database.
Same questions in the comments of my website

Resources