twitter4j error - connect timed out - twitter4j

I am using the twitter4j code and I get connect timed out for making about 5 queries a day.
I am using twitter4j with a servlet and I get the error a lot with timeout.
What happens is that I run the code and the system provides the error when searching and hence the system stops and no more details are provided.
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
try {
Query query = new Query(searchTerm);
twitter4j.QueryResult result1;
do {
result1 = twitter.search(query);
List<Status> tweets = result1.getTweets();
int i=0;int maxint = 20;
for (Status tweet : tweets) {
i++;
if (i<maxint)
{
out.println("procvess");
xmlStr=xmlStr+"<tweet>";
String tweetText = tweet.getText();
tweetText=cleanStringData(tweetText );
HashtagEntity[] hashtags = tweet.getHashtagEntities();
URLEntity[] urls = tweet.getURLEntities();
Date createdDate = tweet.getCreatedAt();
User twitteruser = tweet.getUser();
long tweetId = tweet.getId();
long id1 = tweet.getInReplyToStatusId();
long id2 = tweet.getInReplyToUserId();
String userImageURL = twitteruser.getProfileImageURL();
String userProfileURL = "http://twitter.com/"+twitteruser.getScreenName();
String realname = twitteruser.getName();
String authorname = twitteruser.getScreenName();
Calendar cal = Calendar.getInstance();
cal.setTime(createdDate);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
String tweetDateStr = String.valueOf(year)+"/"+String.valueOf(month)+"/"+String.valueOf(day);
int l=0;
xmlStr=xmlStr+"</tweet>";
}
// System.out.println("#" + tweet.getUser().getScreenName() + " - " + tweet.getText());
}
} while ((query = result1.nextQuery()) != null);
} catch (TwitterException te) {
te.printStackTrace();
out.println("Failed to search tweets: " + te.getMessage());
// return "<error>" + te.getMessage()+"</error>";
}

Related

How do I connect my Zoho Flow Custom Deluge Function? I keep getting error 57 (Unauthorized Access)

I am working on a project that involves Zoho Flow. We created a custom function that should update the item stock and status based on the sales order. However, when I try to run it I get error 57 (Unauthorized Access). I've tried multiple things and it still doesn't work. The connection seems fine when I tested it but it still work run.
See code below:
string Update_stock_or_change_inactive_item(string salesOrderId, string organization)
{
output = "";
salesOrder = zoho.inventory.getRecordsByID("SalesOrders",organization,salesOrderId);
output = salesOrder + " ";
productDetails = ifnull(salesOrder.get("line_items"),"");
lineitems = productDetails.toJSONList();
for each item in lineitems
{
itemMap = item.toMap();
productId = ifnull(itemMap.get("product_id"),"");
productName = ifnull(itemMap.get("name"),"");
quantity = ifnull(itemMap.get("quantity"),"0");
product = zoho.inventory.getRecordsByID("Items",organization,productId);
productMap = product.toMap();
//get product stock
availableStock = ifnull(productMap.get("actual_available_stock"),"0");
availableStockForSale = ifnull(productMap.get("actual_available_for_sale_stock"),"0");
status = ifnull(productMap.get("status"),"");
output = output + status;
//check and update stock
if(availableStock < quantity || availableStockForSale < quantity)
{
//update item to ensure that it is in stock
new_values = Map();
new_values.put("actual_available_stock",quantity);
new_values.put("actual_available_for_sale_stock",quantity);
new_values.put("status","active");
response = zoho.inventory.updateRecord("Items",organization,productId,new_values);
output = output + productName + " - stock updated to " + quantity + ", ";
}
else if(status != "active")
{
new_values.put("status","active");
output = output + productName + " - status updated to active, ";
}
else
{
output = output + productName + " stock not updated, ";
}
}
return output;
}

get_value of a feature in IFeatureCursor

I'm trying to read the attribute "POSTCODE" of the features in IFeatureCursor. The FID was successful read but the "POSTCODE" was failed. The runtime error 'An expected Field was not found or could not be retrieved properly. Appreciate your advise. Paul
private void test2(IFeatureCursor pFeatc1)
{
IFeature feature = null;
IFields pFields;
int ctcur = 0;
while ((feature = pFeatc1.NextFeature()) != null)
{
pFields = feature.Fields;
int indxid = pFields.FindField("FID");
int indxpost = pFields.FindField("POSTCODE");
object valu = feature.get_Value(indxid);
string valupost = feature.get_Value(indxpost);
string aValu = Convert.ToString(valu);
Debug.WriteLine("FID: " + aValu + " Postcode: " + valupost);
ctcur++;
feature = pFeatc1.NextFeature();
}
MessageBox.Show("count cursor = " + ctcur);
}
I have modified the program and successfully read the feature attribute 'POSTCODE'. I have added IFeatureClass.Search(queryFilter, true) to search the feature again by FID and save in a cursor then use the 'feature.get_Value' to read the attribute. Please see my updated code below. Thanks.
private void test2(IFeatureCursor pFeatc1)
{
IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;
IMap map = mxdoc.FocusMap;
IFeatureLayer flayer;
IMaps pMaps = mxdoc.Maps;
for (int i = 0; i <= pMaps.Count - 1; i++)
{
map = pMaps.get_Item(i);
IEnumLayer pEnumLayer = map.get_Layers(null, true);
pEnumLayer.Reset();
ILayer pLayer = pEnumLayer.Next();
while (pLayer != null)
{
if (pLayer.Name == "AddrKey")
{
Debug.WriteLine("Layer: " + pLayer.Name);
flayer = (IFeatureLayer)pLayer;
IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
IFeature feature = null;
IFields pFields;
while ((feature = pFeatc1.NextFeature()) != null)
{
pFields = feature.Fields;
int indx = pFields.FindField("FID");
object valu = feature.get_Value(indx);
string sFID = Convert.ToString(valu);
IQueryFilter queryFilter = new QueryFilter();
queryFilter.WhereClause = ("FID = " + sFID);
Debug.WriteLine("FID: " + sFID);
queryFilter.SubFields = "POSTCODE";
int fieldPosition = pFeatureClass.FindField("POSTCODE");
IFeatureCursor featureCursor = pFeatureClass.Search(queryFilter, true);
while ((feature = featureCursor.NextFeature()) != null)
{
MessageBox.Show(feature.get_Value(fieldPosition));
}
feature = pFeatc1.NextFeature();
}
}
pLayer = pEnumLayer.Next();
}
}
}

Entity Framework not saving to the database

I have a challenge that I am trying to update a record from database But it is not saving to the database, and not showing any errors, it is giving a message that it has updated the record but there are no changes to the database. My code is as below. Any suggestions
dbEntities context = new dbEntities();
var query = context.ConsultantsProfiles.SingleOrDefault(c => c.Username == username);
if (query != null)
{
query.Summary = txtSummary.Text;
query.CareerTitle = txtTitle.Text;
query.ConsultantType = cbType.Text;
query.Username = username;
query.FirstName = txtFirstname.Text;
query.LastName = txtLastName.Text;
query.Email = txtEmail.Text;
query.DateofBirth = Convert.ToDateTime(dptDateofBirth.Value);
query.PhoneNumber = txtPhoneNumber.Text;
query.Website = txtWebsite.Text;
query.Town = txtTown.Text;
query.Country = txtCountry.Text;
if (FileUpload1.HasFile)
{
//image upload
HttpPostedFile postedFile = FileUpload1.PostedFile;
// HttpPostedFile postedFile = uploadControl.UploadedFiles[i];
Stream stream = postedFile.InputStream;
BinaryReader reader = new BinaryReader(stream);
byte[] imgByte = reader.ReadBytes((int)stream.Length);
int imglength = FileUpload1.PostedFile.ContentLength;
query.ProfilePhoto = imgByte;
}
context.ConsultantsProfiles.Attach(query);
context.Entry(query).State = EntityState.Modified;
context.SaveChanges();
}
Response.Write("<script language=javascript>alert('Notification: The Profile Has been Updated');</script>");
}
dbEntities context = new dbEntities();
var consultantProfile = new ConsultantProfile
{
Summary = txtSummary.Text;
CareerTitle = txtTitle.Text;
ConsultantType = cbType.Text;
Username = username;
FirstName = txtFirstname.Text;
LastName = txtLastName.Text;
Email = txtEmail.Text;
DateofBirth = Convert.ToDateTime(dptDateofBirth.Value);
PhoneNumber = txtPhoneNumber.Text;
Website = txtWebsite.Text;
Town = txtTown.Text;
Country = txtCountry.Text;
}
if (FileUpload1.HasFile)
{
//image upload
HttpPostedFile postedFile = FileUpload1.PostedFile;
// HttpPostedFile postedFile = uploadControl.UploadedFiles[i];
Stream stream = postedFile.InputStream;
BinaryReader reader = new BinaryReader(stream);
byte[] imgByte = reader.ReadBytes((int)stream.Length);
int imglength = FileUpload1.PostedFile.ContentLength;
consultantProfile.ProfilePhoto = imgByte;
}
context.Entry(ConsultantsProfiles).State = EntityState.Modified;
context.SaveChanges();

Crystal Report: Failed to load from data database

I am using this code but gives me this error:
Failed to retrieve data from the database. Details: [Database Vendor Code: 201 ]
public JsonResult ReportCertificateOfEmployment(int EmployeeId, int SigId, string SigPosition)
{
string Userkey = "gHeOai6bFzWskyUxX2ivq4+pJ7ALwbzwF55dZvy/23BrHAfvDVj7mg ";
string PassKey = "lLAHwegN8zdS7mIZyZZj+EmzlkUXkvEYxLvgAYjuBVtU8sw6wKXy2g ";
string rptlogin = ConfigurationManager.AppSettings.Get("rptlogin");
string rptPassword = ConfigurationManager.AppSettings.Get("rptPassword");
MemoryStream oStream;
CertificateOfEmployment rpt = new CertificateOfEmployment();
rpt.Refresh();
rpt.SetDatabaseLogon(rptlogin, rptPassword);
rpt.SetParameterValue(0, EmployeeId);
rpt.SetParameterValue(1, SigId);
rpt.SetParameterValue(2, SigPosition);
rpt.SetParameterValue(3, DateTime.Now);
oStream = (MemoryStream)rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); --------- this gives me an error
// extract only the fielname
string filename = Convert.ToString((DateTime.Now.Month) + Convert.ToString(DateTime.Now.Day) + Convert.ToString(DateTime.Now.Year) + Convert.ToString(DateTime.Now.Hour) + Convert.ToString(DateTime.Now.Minute) + Convert.ToString(DateTime.Now.Second) + Convert.ToString(DateTime.Now.Millisecond)) + "BarangayClearance";
var len = oStream.Length;
// store the file inside ~/App_Data/uploads folder
// var path = Path.Combine(Server.MapPath("~/Content/Images"), fileName);
// file.SaveAs(path);
FileTransferServiceClient client2 = new FileTransferServiceClient();
RemoteFileInfo rmi = new RemoteFileInfo();
DateTime dt = DateTime.Now;
// upload file using webservice
DownloadRequest dr = new DownloadRequest();
//web service method to upload a file and return the unique id of the newly uploaded file
string fId = client2.UploadFileGetId("", filename, len, PassKey, Userkey, oStream);
//Instantiate the object Img which is a table in the database server of the application
//Download file using web service;
//DownloadFile in Refence.cs has been edited to return a RemoteFileInfo Class
//before, the return type of DownloadFile method was a Stream type
JsonResult result = new JsonResult();
result.Data = new
{
fileId = fId,
filename = filename
};
rpt.Close();
rpt.Dispose();
var arr = oStream.ToArray();
oStream.Close();
oStream.Dispose();
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return result;
}

Cursor not returning any value,it is showing error?

Am calling readPlaceName from TourGuideController, and passing the string in method readPlaceName(Placename), the cursor is showing null pointer exeception, not showing any values,Can any give solution for this error?
TourGuideController.java
public Cursor readPlaceName(String place_name){
String sql = "SELECT * FROM " + TourGuideDatabasehandler.VISTING_INBETWEEN_PLACES +
" WHERE "+ TourGuideDatabasehandler.PLACE_NAME + " = '" + place_name+"'";
Log.e("","Sql "+sql);
Cursor v = database.rawQuery(sql,null);
Log.e("v","Cursor v : "+v.toString());
return v;
}
MainActivity.java
protected void onPostExecute(Void result) {
super.onPostExecute(result);
int time = t_time;
TourGuideController dbcon = new TourGuideController(ourcontext);
System.out.println("dbcon"+dbcon+"temp_dbcon"+dbcon);
Log.e("OPEN","DB OPEN "+dbcon);
String place = "Juhu Beach";
Cursor cursors = dbcon.readPlaceName(place);
Log.e("dpopen", "cursor"+cursors);
Log.e("Updating cursor and cursor", DatabaseUtils.dumpCursorToString(cursors));
Integer wait_time = null;
while(cursors.moveToNext())
{
wait_time = Integer.parseInt(cursors.getString(8));
}
cursors.close();
String google_distance_time = "5";
Integer google_time = null;
google_time = Integer.parseInt(google_distance_time);
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm");
LocalTime time1 = formatter.parseLocalTime(start_time);
System.out.println("wait_time"+wait_time);
int pred_time = (wait_time) + (google_time);
int get_total_time = (time)-(pred_time);
total_time = String.valueOf(get_total_time);
int addTimeMin = pred_time;
time1 = time1.plusMinutes(addTimeMin);
prediction_time = String.valueOf(time1);
dbcon.updateDateTime(place, start_date, start_time,google_distance_time,prediction_time,total_time);
Cursor cursor2 = dbcon.readPlaceName(place);
Log.e("Updating time and date", DatabaseUtils.dumpCursorToString(cursor2));
}
}}