Invalid Client Data in BingAd request - java

I am trying to call bing ads for performance reports. Idea is to print all KPI details of the keywords. Should i require to set any more parameters in the request call?
I set all the parameters are explained in the bing document.
PasswordAuthentication passwordAuthentication
= new PasswordAuthentication(USER_NAME, PASSWORD);
authorizationData.setAuthentication(passwordAuthentication);
authorizationData.setCustomerId(customerId);
authorizationData.setAccountId(accountId);
authorizationData.setDeveloperToken(DEVELOPER_TOKEN);
ServiceClient<IAdInsightService> adInsightService = new ServiceClient<IAdInsightService>(
authorizationData,
IAdInsightService.class);
GetHistoricalKeywordPerformanceRequest getHistoricalKeywordPerformanceRequest = new GetHistoricalKeywordPerformanceRequest();
try {
GetHistoricalKeywordPerformanceResponse historicalKeywordPerformance = adInsightService.getService().getHistoricalKeywordPerformance(getHistoricalKeywordPerformanceRequest);
ArrayOfKeywordHistoricalPerformance keywordHistoricalPerformances = historicalKeywordPerformance.getKeywordHistoricalPerformances();
List<KeywordHistoricalPerformance> keywordHistoricalPerformances1 = keywordHistoricalPerformances.getKeywordHistoricalPerformances();
for (Iterator<KeywordHistoricalPerformance> iterator = keywordHistoricalPerformances1.iterator(); iterator.hasNext();) {
KeywordHistoricalPerformance performance = iterator.next();
ArrayOfKeywordKPI keywordKPIs = performance.getKeywordKPIs();
for (Iterator<KeywordKPI> iterator1 = keywordKPIs.getKeywordKPIs().iterator(); iterator1.hasNext();) {
KeywordKPI kPI = iterator1.next();
System.out.println("Impressions " + kPI.getImpressions());
}
}
} catch (Exception ex) {
}
When running it throws below exception.
com.microsoft.bingads.v10.adinsight.ApiFaultDetail_Exception: Invalid client data. Check the SOAP fault details for more information
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.apache.cxf.interceptor.ClientFaultConverter.processFaultDetail(ClientFaultConverter.java:182)
at org.apache.cxf.interceptor.ClientFaultConverter.handleMessage(ClientFaultConverter.java:82)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:113)
at org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor.handleMessage(SOAPHandlerInterceptor.java:140)
at org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor.handleMessage(SOAPHandlerInterceptor.java:71)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:798)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1638)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1527)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1330)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:638)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:138)
at com.sun.proxy.$Proxy59.getHistoricalKeywordPerformance(Unknown Source)
at test.BingApi.main(BingApi.java:88)

For starters you'll need to specify the required elements in the GetHistoricalKeywordPerformance request i.e. Keywords, Language, and MatchTypes. If you are still blocked, try using a web traffic capture tool to view the SOAP request and response. For more information please see the troubleshooting guide. I hope this helps!

Related

java.lang.RuntimeException: java.net.SocketTimeoutException: Read timed out

I am developing a project using Eclipse Java EE, Maven and Geotools. This is the part of the code that I am going to talk about:
Map connectionParameters = new HashMap();
// Connection parameters
connectionParameters.put(WFSDataStoreFactory.URL.key, getCapabilities );
connectionParameters.put(WFSDataStoreFactory.PROTOCOL.key, false );
connectionParameters.put(WFSDataStoreFactory.LENIENT.key, true );
connectionParameters.put(WFSDataStoreFactory.MAXFEATURES.key, 30);
connectionParameters.put(WFSDataStoreFactory.TIMEOUT.key, 600000);
try { // The WFSDataStoreFactory dsf is already created before
WFSDataStore dataStore = dsf.createDataStore(connectionParameters);
// We get the source and then the features from it
SimpleFeatureSource source = dataStore.getFeatureSource("gmgml_AREAOBRA");
FeatureCollection<SimpleFeatureType, SimpleFeature> fc = source.getFeatures();
// We try to go one by one and print to see if it really exists
while(fc.features().hasNext()){
SimpleFeature sf = fc.features().next();
System.out.println(sf.getAttribute("IDOBRA")); } // It crashes
The thing is that I read every post about the next error that gives me after crashing:
> SEVERE: Failed to execute request http://mapa20.ewise.es/WFS_EGIOS_SITUATIONROOM/
service.svc/get?TYPENAME=gmgml%3AAREAOBRA&REQUEST=GetFeature&OUTPUTFORMAT=text%2
Fxml%3B+subtype%3Dgml%2F3.1.1&VERSION=1.1.0&SERVICE=WFS
java.lang.RuntimeException: java.net.SocketTimeoutException: Read timed out
at org.geotools.data.store.ContentFeatureCollection.features(ContentFeatureColl
ection.java:176)
at org.geotools.data.store.ContentFeatureCollection.features(ContentFeatureColl
ection.java:58)
at com.sitep.imi.acefat.server.daemon.InsertarBBDDDaemon.dataAccess(InsertarBBD
DDaemon.java:229)
at com.sitep.imi.acefat.server.daemon.InsertarBBDDDaemon.insertData(InsertarBBD
DDaemon.java:98)
at com.sitep.imi.acefat.App.main(App.java:17)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnectio
n.java:1535)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection
.java:1440)
at org.geotools.data.ows.SimpleHttpClient$SimpleHTTPResponse.<init>(SimpleHttpC
lient.java:171)
at org.geotools.data.ows.SimpleHttpClient.get(SimpleHttpClient.java:102)
at org.geotools.data.ows.AbstractOpenWebService.internalIssueRequest(AbstractOp
enWebService.java:426)
at org.geotools.data.wfs.internal.WFSClient.internalIssueRequest(WFSClient.java
:286)
at org.geotools.data.wfs.internal.WFSClient.issueRequest(WFSClient.java:326)
at org.geotools.data.wfs.WFSFeatureSource.getReaderInternal(WFSFeatureSource.ja
va:256)
at org.geotools.data.store.ContentFeatureSource.getReader(ContentFeatureSource.
java:634)
at org.geotools.data.store.ContentFeatureCollection.features(ContentFeatureColl
ection.java:173)
But I cannot find a specific answer for my problem.

PatternSyntaxException when trying to access Website with HtmlUnit

I'm currently trying to acces a Webpage in Javacode using HtmlUnit. The Page has a Button, which opens a new Page when clicked. But when I try to click it, the compiler throws this exception which can be found in the attached image. As far as I understand, it has something to do with illegal escape sequences in the page's Html code.
Here is my code so far:
try(WebClient client = new WebClient(BrowserVersion.CHROME)){
client.getOptions().setCssEnabled(false);
WebRequest webRequest = new WebRequest(url);
webRequest.setCharset("utf-8");
HtmlPage entrypage = client.getPage(webRequest);
HtmlInput dwnld = (HtmlInput) entrypage.getElementById("btn_download");
long millis = System.currentTimeMillis();
while (System.currentTimeMillis() <= millis+11000) {
//Do nothing, just wait 11 seconds
}
if (dwnld != null) {
System.out.println("Found btn_download");
dwnld.click();
}
} catch (FailingHttpStatusCodeException | IOException e ) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Ideas anyone?
Here's the exception:
java.util.regex.PatternSyntaxException: Illegal octal escape sequence near index 2
\0+$
^
at java.util.regex.Pattern.error(Pattern.java:1955)
at java.util.regex.Pattern.o(Pattern.java:3192)
at java.util.regex.Pattern.escape(Pattern.java:2300)
at java.util.regex.Pattern.atom(Pattern.java:2198)
at java.util.regex.Pattern.sequence(Pattern.java:2079)
at java.util.regex.Pattern.expr(Pattern.java:1996)
at java.util.regex.Pattern.compile(Pattern.java:1696)
at java.util.regex.Pattern.<init>(Pattern.java:1351)
at java.util.regex.Pattern.compile(Pattern.java:1054)
at com.gargoylesoftware.htmlunit.javascript.regexp.HtmlUnitRegExpProxy.doAction(HtmlUnitRegExpProxy.java:102)
at com.gargoylesoftware.htmlunit.javascript.regexp.HtmlUnitRegExpProxy.action(HtmlUnitRegExpProxy.java:74)
at net.sourceforge.htmlunit.corejs.javascript.NativeString.execIdCall(NativeString.java:455)
at net.sourceforge.htmlunit.corejs.javascript.IdFunctionObject.call(IdFunctionObject.java:89)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1531)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3057)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:724)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:832)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:733)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:708)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:982)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:351)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:411)
at com.gargoylesoftware.htmlunit.html.HtmlScript$3.execute(HtmlScript.java:276)
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:290)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:793)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:751)
at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1170)
at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1072)
at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206)
at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:330)
at org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3126)
at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2093)
at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:920)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:1017)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:248)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:194)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:156)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:471)
at com.gargoylesoftware.htmlunit.WebClient.loadDownloadedResponses(WebClient.java:2110)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:875)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.processPostponedActions(JavaScriptEngine.java:962)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1327)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1270)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1218)
at src.Hosts$1.exctractFileLinkFrom(Hosts.java:44)
at src.TestMain.main(TestMain.java:10)
Possible solution?!
It is possible that the Error here does not lie in the frameworks Htmlparsing. My sugggestion is, that not the HtmlUnit framework itself is unable to parse illegal escape sequences but it's logger might be.
I didn't intended to solve the problem this way, but when I changed the loggers level to SEVERE to clean up my console output, there is no such exception being thrown.
Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.SEVERE);
Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.SEVERE);
Is my suggestion here correct or is this just coincidence?

List all the lotus notes database

I tried to create a lotus notes client using Java. Now, I have a problem to list all the user defined databases. What I tried to do is
// testing purpose
private void printAllDb() throws NotesException
{
DbDirectory dir = session.getDbDirectory(host);
String server = dir.getName();
if(server.equals(""))
{
server = "Local";
}
System.out.println("database direcory list on server (" + server + ")");
Database db = dir.getFirstDatabase(DbDirectory.DATABASE);
do
{
System.out.println("file name: " + db.getFileName().toUpperCase() + " - " + db.getTitle());
} while((db = dir.getNextDatabase()) != null);
}
However, the program will throw the exception:
Exception in thread "main" NotesException: Server access denied
at lotus.domino.NotesExceptionHelper.read(Unknown Source)
at lotus.domino.NotesExceptionHolder._read(Unknown Source)
at lotus.priv.CORBA.iiop.RepImpl.invoke(Unknown Source)
at lotus.priv.CORBA.portable.ObjectImpl._invoke(Unknown Source)
at lotus.domino.corba._IDbDirectoryStub.getFirstDatabase(Unknown Source)
at lotus.domino.cso.DbDirectory.getFirstDatabase(Unknown Source)
at nz.co.sylresearch.sylsearch.agents.lotusnotes.LotusNotesAPIHandler.printAllDb(LotusNotesAPIHandler.java:58)
at nz.co.sylresearch.sylsearch.agents.lotusnotes.LotusNotesAPIHandler.main(LotusNotesAPIHandler.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
The issue is pretty clear. You are getting an access denied error to the server. The tricky part now is figuring out why.
You should start with making sure the username and password used to create the session object is correct. Then make sure that user has access to the server and has access to run Java code on the server. You'll have to check the server document in the Directory for that.

Activating a user account on creation in AD LDS

So, I'm writing code that will create user accounts in AD LDS. I can create the user, but the account is disabled.
I want the user to be active and to be able to change their password. I've tried some of the things suggested in this post, but it hasn't helped me.
Here's my code:
ctx = getConnection(adminUser, adminPassword);
// Create attributes for the new user
Attributes attributes = new BasicAttributes(true);
// Main attributes for user
attributes.put("objectClass", "user");
attributes.put("name", user.getFullName());
attributes.put("ms-DS-User-Account-Control-Computed",
Integer.toString(UF_NORMAL_ACCOUNT + UF_PASSWORD_EXPIRED));
try {
ctx.createSubcontext(getDistinguishedName(user.getFullName()),
attributes);
System.out.println("User successfully added!");
} catch (NamingException e) {
e.printStackTrace();
}
When I run this, I get the following error:
javax.naming.directory.NoSuchAttributeException: [LDAP: error code 16
- 00000057: LdapErr: DSID-0C090D11, comment: Error in attribute conversion operation, data 0, v23f0remaining name 'CN=Samuel
King,CN=Users,CN=Agents,DC=CHESA,DC=local' at
com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source) at
com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source) at
com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source) at
com.sun.jndi.ldap.LdapCtx.c_createSubcontext(Unknown Source) at
com.sun.jndi.toolkit.ctx.ComponentDirContext.p_createSubcontext(Unknown
Source) at
com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(Unknown
Source) at
com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(Unknown
Source) at
javax.naming.directory.InitialDirContext.createSubcontext(Unknown
Source) at
com.ceiwc.ActiveDirectory.createUserAccount(ActiveDirectory.java:114)
at com.ceiwc.TestAD.main(TestAD.java:24)
If I change the line where I'm updating the ms-DS-User-Account-Control-Computed to:
attributes.put("ms-DS-User-Account-Control-Computed", UF_NORMAL_ACCOUNT
+ UF_PASSWORD_EXPIRED);
i get the following error:
javax.naming.directory.InvalidAttributeValueException: Malformed
'ms-DS-User-Account-Control-Computed' attribute value; remaining name
'CN=Samuel King,CN=Users,CN=Agents,DC=CHESA,DC=local' at
com.sun.jndi.ldap.LdapClient.encodeAttribute(Unknown Source) at
com.sun.jndi.ldap.LdapClient.add(Unknown Source) at
com.sun.jndi.ldap.LdapCtx.c_createSubcontext(Unknown Source) at
com.sun.jndi.toolkit.ctx.ComponentDirContext.p_createSubcontext(Unknown
Source) at
com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(Unknown
Source) at
com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(Unknown
Source) at
javax.naming.directory.InitialDirContext.createSubcontext(Unknown
Source) at
com.ceiwc.ActiveDirectory.createUserAccount(ActiveDirectory.java:116)
at com.ceiwc.TestAD.main(TestAD.java:24)
So, what am I doing wrong? Is this the proper way to activate the account? Does someone have any code to help me out?
Thanks!
NuAlphaMan,
I think, that the exception has something to do with the fact that you use CN as the name of the attribute instead of Ldap-Display-Name which is msDS-User-Account-Control-Computed. The description could be found here http://msdn.microsoft.com/en-us/library/windows/desktop/ms677840(v=vs.85).aspx.
As to the second question of how to activate an account, I've found that there is an attribute userAccountControl (http://msdn.microsoft.com/en-us/library/windows/desktop/ms680832(v=vs.85).aspx#win_2008_r2) and the value 0x00000002 (ADS_UF_ACCOUNTDISABLE) that can disable an account. The only thing that crosses my mind is to try to read the value and flip the bit.
Regards, Dmitry
NoSuchAttributeException: "Indicates that the attribute specified in the modify or compare operation does not exist in the entry."
Malformed 'ms-DS-User-Account-Control-Computed' attribute value: means wrong attribute type.
here is my working example, that i check with ActiveDirectory 2008:
public void mapToContext(int userAccountControl, DirContextAdapter context) {
context.setAttributeValue("userAccountControl", disableAccount(userAccountControl));
}
private String disableAccount(int userAccountControl) {
userAccountControl |= AccountControlFlags.ACCOUNTDISABLE;
return String.valueOf(userAccountControl);
}

Exceptions being thrown with getting a status with twitter4j?

I was trying to follow the docs here: https://github.com/yusuke/twitter4j/blob/master/twitter4j-examples/src/main/java/twitter4j/examples/tweets/ShowStatus.java but appear to have gone wrong somewhere. I'm trying to do something slightly different then the docs however. I am not taking args, and am using a hardcoded username instead. Here is the code that is troubling.
import twitter4j.Twitter;
import twitter4j.Status;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
public class ChrisTwitter {
public Status status;
public ChrisTwitter (){
Twitter twitter = new TwitterFactory().getInstance();
try {
Status status = twitter.showStatus(Long.parseLong("rye761"));
System.out.println("#" + status.getUser().getScreenName() + " - " + status.getText());
}
catch (TwitterException e) {
e.printStackTrace();
}
}
}
any ideas? Oh and here is what I get in the console: (new stack trace)
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems:
TwitterFactory.getInstance cannot be resolved to a type
The method Page(int, int) is undefined for the type ChrisTwitter
at com.github.ryebread761.lockergnome.ChrisTwitter.<init>(ChrisTwitter.java:16)
at com.github.ryebread761.lockergnome.Base$CTListener.actionPerformed(Base.java:121)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6375)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6140)
at java.awt.Container.processEvent(Container.java:2083)
at java.awt.Component.dispatchEventImpl(Component.java:4737)
at java.awt.Container.dispatchEventImpl(Container.java:2141)
at java.awt.Component.dispatchEvent(Component.java:4565)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4619)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4280)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4210)
at java.awt.Container.dispatchEventImpl(Container.java:2127)
at java.awt.Window.dispatchEventImpl(Window.java:2482)
at java.awt.Component.dispatchEvent(Component.java:4565)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:684)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:643)
at java.awt.EventQueue$1.run(EventQueue.java:641)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:657)
at java.awt.EventQueue$2.run(EventQueue.java:655)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:654)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
You're trying to parse an alphanumeric string to long and that's throwing the NumberFormatException:
Status status = twitter.showStatus(Long.parseLong("rye761"));
Since you're not catching a NumberFormatException in your try-catch block the exception propagates. To prevent this you should validate the input you try to parse before doing so or adding an aditional catch for that NumberFormatException.
EDIT
To get the latest tweet of an user, you can take this approach:
First of all define the paging of your request. In this case just ask for one page and one tweet per page (If I'm not mistaken it will be the latest one). Then you issue the request directly, since you're consulting a tweet and you're not doing anything else you don't need to authenticate AFAIK.
Twitter latestTweetChecker = new TwitterFactory.getInstance();
Paging page = Page(1,1);
List<Status> statusList = latestTweetChecker.getUserTimeline("rye761",page);
There, you'll have the status you need. Just grab the information you need with the corresponding methods.
Long.parseLong("rye761")
Even though input for parseLong is of format String, characters in the String must be all decimal digits, which is not case with rye761. So, you are getting exception
The characters in the string must all be decimal digits, except that
the first character may be an ASCII minus sign '-' (\u002D') to
indicate a negative value.

Categories

Resources