I am developing an app that gets Facebook unread inbox message .
The following v2.0 FQL query works fine:
SELECT sender, body FROM unified_message
WHERE thread_id IN
(SELECT thread_id FROM unified_thread WHERE folder = 'inbox' AND unread=1)
AND unread=1
ORDER BY timestamp DESC
As a result, we have a list of all unread messages.
But, Facebook says:
Version 2.0 of the Facebook Platform API is the last version where FQL
will be available. Versions after 2.0 will not support FQL. Please
migrate your applications to use Graph API instead of FQL. Please see
our changelog for current version information.
So, I am looking for a way to do that with Graph API only. I tried the following:
Bundle params = new Bundle();
params.putString("unread", ">0");
new Request(session,"/me/inbox/",params,HttpMethod.GET,new Request.Callback() {
public void onCompleted(Response response) {
...
}
}
).executeAsync();
without success. I get all the threads whereas I only need the unread threads. How to do that then?
I am sorry for the advice I gave when I blindly quoted the following Facebook notice:
However, you should not use FQL anymore:
Version 2.0 of the Facebook Platform API is the last version where FQL will be available. Versions after 2.0 will not support FQL. Please
migrate your applications to use Graph API instead of FQL. Please see
our changelog for current version information.
This statement is true, but to follow it isn't very smart.
Indeed, I checked further and found out:
v2.0 is available until August 7th 2016,
the Graph API is not yet suitable for your current usage.
I didn't expect the Graph API to be so weak. The Graph API makes it impossible to build a request by filtering any field. For example, we can't do simple things such as:
me/threads?unread_count>0,
me/threads?fields=unread_count.more(0).
Right now with Graph, you would have to iterate through all the threads and check which one have unread > 0. You would lose time and bandwidth. Moreover, the message table doesn't even have an unread field which would make it impossible for you to find any specific unread message(s).
So, the best is to keep using FQL. You are safe for now. By 2016, Facebook will probably have improved the way we query with Graph API.
Wait and see...
Related
I used StartApplicationRequest to create a sample request to start the application as given below:
StartApplicationRequest request = StartApplicationRequest.builder()
.applicationId("test-app-name")
.build();
Then, I used the ReactorCloudFoundryClient to start the application as shown below:
cloudFoundryClient.applicationsV3().start(request);
But my test application test-app-name is not getting started. I'm using latest Java CF client version (v4.5.0 RELEASE), but not seeing a way around to start the application.
Quite surprisingly, the outdated version seems to be working with the below code:
cfstatus = cfClient.startApplication("test-app-name"); //start app
cfstatus = cfClient.stopApplication("test-app-name"); //stop app
cfstatus = cfClient.restartApplication("test-app-name"); //stop app
I want to do the same with latest CF client library, but I don't see any useful reference. I referred to test cases written at CloudFoundry official Github repo. I derived to the below code after checking out a lot of docs:
StartApplicationRequest request = StartApplicationRequest.builder()
.applicationId("test-app-name")
.build();
cloudFoundryClient.applicationsV3().start(request);
Note that cloudFoundryClient is ReactorCloudFoundryClient instance as the latest library doesn't support the client class used with outdated code. I would like to do all operations (start/stop/restart) with latest library. The above code isn't working.
A couple things here...
Using the reactor based client, your call to cloudFoundryClient.applicationsV3().start(request) returns a Mono<StartApplicationResponse>. That's not the actual response, it's the possibility of one. You need to do something to get the response. See here for more details.
If you would like similar behavior to the original cf-java-client, you can call .block() on the Mono<StartApplicationResponse> and it will wait and turn into a response.
Ex:
client.applicationsV3()
.start(StartApplicationRequest.builder()
.applicationId("test-app-name")
.build())
.block()
The second thing is that it's .applicationId not applicationName. You need to pass in an application guid, not the name. As it is, you're going to get a 404 saying the application doesn't exist. You can use the client to fetch the guid, or you can use CloudFoundryOperations instead (see #3).
The CloudFoundryOperations interface is a higher-level API. It's easier to use, in general, and supports things like starting an app based on the name instead of the guid.
Ex:
ops.applications()
.start(StartApplicationRequest.builder()
.name("test-app-name").build())
.block();
I want to use the Stripe.com on the server-side. When I try to create card token via
curl https://api.stripe.com/v1/tokens \
-u sk_test_qMabFX3j5ApELqUH8mEy6NDp: \
-d card[number]=4242424242424242 \
-d card[exp_month]=12 \
-d card[exp_year]=2019 \
-d card[cvc]=123
or via
Stripe.apiKey = "sk_test_qMabFX3j5ApELqUH8mEy6NDp";
Map<String, Object> tokenParams = new HashMap<String, Object>();
Map<String, Object> cardParams = new HashMap<String, Object>();
cardParams.put("number", "4242424242424242");
cardParams.put("exp_month", 6);
cardParams.put("exp_year", 2019);
cardParams.put("cvc", "314");
tokenParams.put("card", cardParams);
Token.create(tokenParams);
I see the message in my dashboard:
"We saw nnn requests in the last m days with raw credit card numbers"
My questions are:
1) Can I safely use the Java API to create a card token? If yes, how to avoid such messages?
2) Or I have to use Stripe elements and one of their scripts for this?
QUESTION 1:
Can I safely use the Java API to create a card token? If yes, how to avoid such messages?
ANSWER:
Yes, but it needs the highest level of permission, instead of SAQ A you need SAQ D verification.
Validation Process: https://stripe.com/docs/security#validating-pci-compliance
(Select tab "API Direct")
Summary:
Your transactions must be secure both physically, in code and fill all the requirements (encrypted card information over internet, keep your wifi connection secure, documentation if you are storing card data etc.)
You need to fill out this PDF and upload to Stripe annually: https://www.pcisecuritystandards.org/documents/PCI-DSS-v3_2_1-SAQ-D_Merchant.pdf
Your application should have PCI DSS Compliance and has to be filled in to the form above and be versioned: https://www.pcicomplianceguide.org/faq/
If you got over 6 million transactions a year, you must fill out this PDF once a year: https://www.pcisecuritystandards.org/documents/PCI-DSS-v3_2_1-ROC-Reporting-Template.pdf
As I understand this should also remove the message in the Stripe dashboard you are referring to.
Stripe's Radar functionality will not work
For reference, the API endpoint documentation:
Create a token: https://stripe.com/docs/api/tokens/create_card
Create a charge: https://stripe.com/docs/api/charges/create
QUESTION 2:
Or I have to use Stripe elements and one of their scripts for this?
ANSWER:
No, you don't have to. Only if you want a faster solution with lower level of permissions and less struggle, you can use the pre built Stripe element scripts.
ADDITIONAL INFORMATION:
Using Stripe.js v2 (Not JAVA but Javascript) to collect card information yourself and create a token, SAQ A-EP is required which needs a lower level of permission then the API which has SAQ D. See: https://www.pcisecuritystandards.org/documents/PCI-DSS-v3_2_1-SAQ-A_EP.pdf
But using Stripe.js v2 without Element is deprecated: https://stripe.com/docs/stripe-js/v2
So I do not know if this will remove the security warning in dashboard and the functionality could be removed later. So the safest way to go if you require to handle Card Information yourself is getting the SAQ D verification and fill out the forms annually. (For a website shop this should not be necessary and you should go with Elements, but for custom hardware integrations like Terminals, NFC scanners etc, this could be the simplest / only way to go if you have to integrate yourself).
If you create card tokens server-side in Java, this means that your servers received raw card details. Even if you don't save the information in your database, you still fall under a higher level of PCI compliance which would be a lot of work to comply with.
Instead, you should tokenize client-side, using Elements or Checkout. This would let you create a card token securely client-side and then send that token to your server. This would also let you fall under SAQ-A which is the easiest level for PCI compliance. You can read more about the differences in Stripe's docs here.
Can someone help me with name of api which enables realtime prediction of a model. Please note that i am not requesting for RealtimeEndpointRequest object. i have gone through the entire documentation of AWS Machine Learning SDK but haven't found any thing.
Edit 1 :
This is the code that i have used -
CreateRealTimePrediction createRealTimePrediction ;
CreateRealtimeEndpointRequest createRealtimeEndPointReq;
CreateRealtimeEndpointResult createRealtimeEndPointRes;
PredictRequest predReq;
String mlModelId="ml-Lkqmcs8cM2W";
createRealtimeEndPointReq.setMLModelId(mlModelId);
PredictResult predRes = null;
Map<String,String> record=null;
// assume i have set a record in the Map.
createRealtimeEndPointRes = amlClient.createRealtimeEndpoint(createRealtimeEndPointReq);
String predictEndpoint=createRealtimeEndPointRes.getRealtimeEndpointInfo().getEndpointUrl();
predReq= new PredictRequest();
predReq.setMLModelId(mlModelId);
for (int i=0;i<recordKeys.length;i++){
record.put(recordKeys[i],recordValues[i]);
}
predReq.setRecord(record);
predReq.setPredictEndpoint(predictEndpoint);
predRes=amlClient.predict(predReq);
return predRes;
}
Now what is happening is - if i enable the real time prediction by using aws management console manually and then run this segment of code, then the results are generated as expected but when i the realtime prediction is disabled, then i get this error -
Exception in thread "main" com.amazonaws.services.machinelearning.model.PredictorNotMountedException: Either ML Model with id ml-Lkqmcs8
cM2W is not enabled for real-time predictions or the MLModelId is invalid. (Service: AmazonMachineLearning; Status Code: 400; Error Code
: PredictorNotMountedException; Request ID: 2dc70e58-07d0-11e5-a0c7-bb93f17d1b2e)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1160)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:748)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:467)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:302)
at com.amazonaws.services.machinelearning.AmazonMachineLearningClient.invoke(AmazonMachineLearningClient.java:1995)
at com.amazonaws.services.machinelearning.AmazonMachineLearningClient.predict(AmazonMachineLearningClient.java:637)
at com.nrift.aml.prediction.realtime.CreateRealTimePrediction.createRealTimePrediction(CreateRealTimePrediction.java:61)
at RealTimePrediction.main(RealTimePrediction.java:53)
which effectively means that this segment of code is not enabling the real time prediction though i have used
CreateRealtimeEndpoint
api in it.
P.s- the code segment i have posted is a not complete, the complete code is working correctly so you can make assumptions about the correctness of code.
The API you are looking for is CreateRealtimeEndpoint. Creating a real-time endpoint is the mechanism for enabling the model to be used for real-time predictions. When you no longer need to use this model, you can destroy the endpoint with the DeleteRealtimeEndpoint API. The model always stays intact, so you can create/delete endpoints when needed.
I want to use java and Twitter API to collect Twitter data for researching, especially to collect tweets sent by a given Twitter ID.
Now I can only collect my own tweets by using Twitter4j and OAuth setting. How could I get others tweets if I could not get their OAuth?
There is no restriction to collect others tweets, so what I mean is you don't need to have a specific authhentication token for this. Only restriction might be protected accounts owners because protected accounts don't allow anyone to get their tweets without establishing friendship association like following mechanism.
You can look at both dev.twitter.com and twitter4j sites how to do that. By the way, I recommend twitter4j. If you have further questions, let me know I can help more as well.
Java4j Code Examples
The method you're looking for is:
getUserTimeline(java.lang.String screenName)
or:
getUserTimeline(long userId)
This will give you the latest 20 Tweets of the required user. So your code should look something like this:
Twitter twitterConnection = getConnection(); //I assume you already know how to init a connection
ResponseList<Status> results = twitterConnection.getUserTimeline("justinbieber");
Greetings,
I am creating a Java based server to create push notifications for Apple's iOS APNs service. I have found Javapns on google code which seems to provide a simple basic framework to communicate with APNs, and which seems to be fairly wide used.
http://code.google.com/p/javapns/
However, reading Apple's docs, there is an "enhanced format" for notifications which supports "expiry" i.e. setting a time (well, in seconds) for a notification to expire if it hasn't yet been delivered. I do not see any way to set this using Javapns, and I am unsure how the APNs service handles expiry of notifications if you do not explicitly set it. So,
Does anyone know how to support the enhanced notification format of APNs specifically how to set the expiry?
Does anyone know how Apple handles notification expiry if it isn't explicitly set?
Does anyone have any suggestions that don't require me to start from scratch, as the server is currently functional as is?
Thanks in advance.
Andrew
I have recently made substantial contributions to the JavaPNS project, which lead to the release of JavaPNS 2.0 a few days ago. That version provides full support for the enhanced notification format, including the ability to set your own expiry.
Sylvain
Nice that you found the java library... to bad you didn't read the docs there.
I'll post some of the highlights below:
The existing code uses the 'Simple notification format' which does not return an error EVER.
See docs at:
http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html
I've tried updating to the 'Enhanced notification format' which is supposed to return an error, but I'm unable to get any errors back from the APNS. (also in the link above)
With the Enhanced format, the connection isn't being dropped immediately after sending data, but I'm not getting anything back from my socket.getInputSocket.read() call.
This issue will have to be tabled until I have more time to troubleshoot.
(Someone else commented)
Thanks a lot for looking into it.
I got the same result as yours. Maybe it has something to do with Apple Gateway.
So... you could:
1) Build your own
2) Help improve the existing library
3) Try another library like: https://github.com/notnoop/java-apns
4) Do nothing
Enhanced ios push here.
To send a notification, you can do it in three steps:
Setup the connection
ApnsService service =
APNS.newService()
.withCert("/path/to/certificate.p12", "MyCertPassword")
.withSandboxDestination()
.build();
Create and send the message
String payload = APNS.newPayload().alertBody("Can't be simpler than this!").build();
String token = "fedfbcfb....";
service.push(token, payload);
To query the feedback service for inactive devices:
Map<String, Date> inactiveDevices = service.getInactiveDevices();
for (String deviceToken : inactiveDevices.keySet()) {
Date inactiveAsOf = inactiveDevices.get(deviceToken);
...
}