How to get tweets by hashtag? - javascript

I would like to get multiple tweets of some hashtag, for example "iPhone".
Use the following code, but this will result in an error that sends the URL in red.
$.ajax({
type: "GET",
dataType: "jsonp",
cache: false,
url: "http://search.twitter.com/search.json?q=iPhone&count=100",
success: function(response) {
console.log(response);
},
error: function(data) {
console.log('We have a problem!');
}
});

Is your error
{"errors":[{"code":215,"message":"Bad Authentication data."}]}
Please refer https://dev.twitter.com/rest/public/search:- Please note that now API v1.1 requires that the request must be authenticated, check Authentication & Authorization documentation for more details on how to do it.

use titter4j library and following code
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("your key")
.setOAuthConsumerSecret(
"your key")
.setOAuthAccessToken(
"your key")
.setOAuthAccessTokenSecret(
"your key");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
Query query = new Query("#iphone7");
query.setCount(100);
try {
result = twitter.search(query);
tweets.addAll(result.getTweets());
System.out.println("Gathered " + tweets.size() + " tweets");
} catch (TwitterException te) {
System.out.println("Couldn't connect: " + te.toString());
}

Related

Why I'am always getting "Duplicate Alert" error after doing update request?

I am writing Chrome Extension for Vtiger CRM.
I need to create ability to add value for "Proposal text" field in the CRM on project page.
Here is the docs: https://www.vtiger.com/docs/rest-api-for-vtiger#/Update
How I do it:
Get the project from Vtiger API.
Change value "cf_potentials_proposaltext" in the project object.
Make POST (as required by docs) request to update Vtiger API endpoint, send updated project object
Get "duplicate alert" response..
I am absolutely sure, since I checked that I am sending the modified project object - using the console.log 'Temprorary_1' (in vtigerAddProposal) and 'Temprorary_2'(in vtigerUpdatePotential), also checked changed value in Chrome dev console in Network tab..
Here is my code:
function vtigerAddProposal() {
var temprorary_potential;
var dialog = $('#dialog');
chrome.storage.sync.get(['proposal'], function(result) {
$.ajax( {
url: 'https://roonyx.od2.vtiger.com/restapi/v1/vtiger/default/retrieve',
type: 'GET',
data: {
'id': localStorage.getItem('vtiger_last_opportunity_id')
},
success: function( response ) {
temprorary_potential = response['result'];
console.log("Temprorary_1: " + JSON.stringify(temprorary_potential, null, 2));
temprorary_potential['cf_potentials_proposaltext'] = result.proposal;
vtigerUpdatePotential(temprorary_potential);
},
error: function (response) {
console.log("Failed to get opportunity from Vtiger.");
$('#dialog-inner-text').text("Vtiger: " + response.status + " " + response.statusText);
dialog.show(800);
console.log(response);
}
});
});
}
function vtigerUpdatePotential(data) {
var dialog = $('#dialog');
console.log("Temprorary_2: " + JSON.stringify(data, null, 2));
// Second Part
$.ajax( {
url: 'https://roonyx.od2.vtiger.com/restapi/v1/vtiger/default/update',
type: 'POST',
data: {
element: JSON.stringify(data)
},
success: function( response ) {
console.log("Successfully updated Vtiger potential.")
console.log(response);
localStorage.removeItem('vtiger_last_opportunity_id'); // в случае успеха удаляем oppId
},
error: function (response) {
console.log("Failed to update potential in Vtiger.")
$('#dialog-inner-text').text("Vtiger potential wasn't update: " + response.status + " " + response.statusText);
dialog.show(800);
console.log(response);
}
});
}
Thank you in advance.
Problem solved by using revise https://www.vtiger.com/docs/rest-api-for-vtiger#/Revise once instead of update. Thanks to #pinaki

Calling Outlook API to Add event to outlook calendar using ajax call

I need to Add an event from my database to outlook calendar for which I have been trying to make an ajax call to the outlook auth API first which looks like this
$scope.authorizeOutlook = function () {
let redirect = 'http://localhost:51419';
let clientId = 'xxx';
var authData = 'client_id=' + clientId + '&response_type=code&redirect_uri=' + redirect + '&response_mode=query&scope=https%3A%2F%2Fgraph.microsoft.com%2Fcalendars.readwrite%20&state=12345';
debugger
$.ajax({
url: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
type: 'POST',
host: 'https://login.microsoftonline.com',
contentType: "application/x-www-form-urlencoded",
contentLength: "600",
data: authData,
success: function (response) {
debugger;
alert(response.status);
//alert("success");
},
error: function (response) {
alert(response.status);
//alert("fail");
}
});
}
But I am getting response status as 0. What does that mean? Where am I doing it wrong?
If you use Oauth2.0, you need to add " token-type: Bearer ".
Reference from:
Get access tokens to call Microsoft Graph

Ajax function give error "Hit error fn! [object Object]" from the following function when calling a webservice

i am new to the webservice and try to call a webservice from html page which give me following error "Hit error fn![object Object]" and cannot sending mail to the desired email address. kindly tell me that whats the error?
function test() {
var firstname=$('#txtName').val();
var lastname =$('#txtMessage').val();
var Email=$('#txtEmail').val();
$.ajax({ url: "http://localhost/ZeroDebt/WsZeroDebtApp.asmx/SendEmailToClient",
data: { _fromAddress: JSON.stringify(Email),_Subject:JSON.stringify("Zero Debt App Invitation Request"),_body:JSON.stringify(firstname +' '+lastname), clientName: JSON.stringify('Dr. Hanoi'), clientEmail: JSON.stringify('abc#xyz.net') },
dataType: "jsonp",
success: function(data) {
alert(data);
},
error: function(error) {
alert("Hit error fn!" + error);
}
});
}
May I suggest to rewrite as such? (Please test yourself)
var SENDMAIL_URL = "http://localhost/ZeroDebt/WsZeroDebtApp.asmx/SendEmailToClient"
function test() {
var firstname = $('#txtName').val(),
lastname = $('#txtMessage').val(),
email = $('#txtEmail').val();
var data = JSON.stringify({
_fromAddress: email,
_Subject: "Zero Debt App Invitation Request",
_body: firstname + ' ' + lastname,
_clientName: 'Dr. Hanoi',
clientEmail: 'abc#xyz.net'
});
function notify( args ) {
console.log( args );
}
function onSuccess( data ) {
notify( data );
}
function onError( error ) {
notify( "Hit error fn!" ); // Important to seperate string from Object
notify( error );
}
$.ajax({
url: SENDMAIL_URL,
data: data,
dataType: "jsonp",
success: onSuccess,
error: onError
});
}
Furthermore it would be maintainable to make your URL a constant string and keep urls together (easier configurable than scrolling through code).
At last, i found a solution. the only thing i need to do is to give email at client email parameter that would not be in string format. write abc#xyz.com instead of "abc#xyz.com".
the correct scenario is:
data: { _fromAddress: JSON.stringify(Email),_Subject:JSON.stringify("Zero Debt App Invitation Request"),_body:JSON.stringify(firstname +' '+lastname), clientName: JSON.stringify('Dr. Hanoi'), clientEmail: abc#xyz.net }

Try to catch all of my contacs using google api v3: ERROR

I need help. I try to catch all of contacs from Google Api V3, Auth2, but it returns this error:
GET https://www.google.com/m8/feeds/contacts/default/full?callback=jQuery171029…+gsession&issued_at=1379496709&expires_at=1379500309&_aa=0&_=1379496719602 401
(Token invalid - AuthSub token has wrong scope)
First I Sign in Google +, and then i try to do the authorization in Google Contacts:
function myContacts() {
var config = {
'client_id': clientId,
'scope': 'https://www.google.com/m8/feeds',
};
gapi.auth.authorize(config, function () {
var authParams = gapi.auth.getToken(); // from Google oAuth
$.ajax({
url: 'https://www.google.com/m8/feeds/contacts/default/full',
dataType: 'jsonp',
type: "GET",
data: authParams,
success: function (data) {
alert("success: " + JSON.stringify(data))
},
error: function (data) {
console.log("error: " + JSON.stringify(data))
}
})
});
}
Is this the correct way to do this?
Thank you
Append access_token into url as request parameter with the token fetched after authorization, instead of sending it to data.
you can't do an hxr (ajax) request given the CORS restriction from goolge.com.
you can use this library to achieve this though. It solves the Oauth login/retrieving contacts from gmail)
http://eventioz.github.io/gcontacts/

linkedin logout function(javascript API) is not working in some conditions

In my website, I have provided a facility to login via linkedin. I have used javascript API for that.
I have written below code for login.
function onLinkedInAuth() {
var isLoggedIn = document.getElementById('<%=hdnIsLoggedin.ClientID %>').value;
// Check for the session on the site
if (isLoggedIn == false || isLoggedIn == 'false') {
IN.API.Profile("me")
.fields("id", "firstName", "lastName", "industry", "emailAddress")
.result(function (me) {
//debugger;
var id = me.values[0].id;
var fname = me.values[0].firstName;
var lname = me.values[0].lastName;
var industry = me.values[0].industry;
var email = me.values[0].emailAddress;
// AJAX call to register/login this user
jQuery.ajax({
type: "POST",
url: "UserRegisterAsSeeker.aspx/LinkedinLoginOrRegister",
data: "{id:'" + id + "',fname:'" + fname + "',lname:'" + lname + "',email:'" + email + "'}",
contentType: "application/json; Characterset=utf-8",
dataType: "json",
async: true,
success: function (data) {
closeLoginWindow();
__doPostBack('<%=lnkRefreshPage.UniqueID%>', '');
},
error: function (request, status, error) {
alert('Unable to process the request at this moment! Please try again later.');
},
complete: function () {
}
});
});
}
}
Above code works fine.
And for logout i have used below function provided by linkedin
function logout() {
IN.User.logout(function () {
window.location.href = '/logout.aspx';
});
}
Problem is in logout. When we login to the site and immediately logout, it works fine but when we leave the site ideal for some time it does not logout from linkedin. We have to click 3-4 times then it works.
I don't know why it's happening. Please help if you can.

Categories

Resources