I am developing a Facebook application. In this application, I use Java API provided by Google and the application is based on web.
I have the facebook_api_key and facebook_secrete, but how to get the sessionKey?
This code is not web-based:
FacebookJsonRestClient client = new FacebookJsonRestClient(Test.API_KEY, Test.SECRET);
String token = client.auth_createToken();
String url = "http://www.facebook.com/login.php?api_key=";
url += Test.API_KEY;
url += "&v=1.0";
url += "&auth_token=";
url += token;
String strCommand = "C:/Program Files/Internet Explorer/IEXPLORE.EXE ";
strCommand += url;
Runtime.getRuntime().exec(strCommand);
// wait until the login process is completed
// fetch session key
String session = client.auth_getSession(token, true);
......
I want to change it to a web-based one.
Why can't you try this way:
String sessionKey = request.getParameter(FacebookParam.SESSION_KEY.toString());
FacebookXmlRestClient client = new FacebookXmlRestClient(FB_API_KEY, FB_SECRET_KEY, sessionKey);
I also suggest the FaceBook Developer Forum Dicussion and an article describe about generating session keys. I thought it could be helpful to you..
Related
I have an ASP application that uploads a PDF file through Request.BinaryRead(Request.TotalBytes). The requests that I make, are made through a java application. The problem is that I have method in Java that iterates through the Header Field Keys of the object HttpURLConnection. When the iteration is made I get in my ASP code an error "cannot call binaryread after using request.form".
Here is my java code:
public String getCookieValue(HttpURLConnection con, String cookieKey) {
String cookieValue = null;
String headerName = null;
for (int i = 1; (headerName = con.getHeaderFieldKey(i)) != null; i++) {
if (headerName.equals("Set-Cookie")) {
String cookie = con.getHeaderField(i);
cookie = cookie.substring(0, cookie.indexOf(";"));
String cookieName = cookie.substring(0, cookie.indexOf("="));
if (cookieName.equals(cookieKey)) {
cookieValue = cookie.substring(cookie.indexOf("=") + 1, cookie.length());
}
}
}
return cookieValue;
}
The exact line of java code that breaks my ASP application is con.getHeaderFieldKey(i). When I upload the file without this Java application, the file is uploaded properly.
What can I do to bypass this issue ?
Thank you
Actually the problem here was that we are using a wrapper for the Session object. When we are trying to retrieve the information regarding the session Id we are using the Request.From method, and this intervenes with the Request.BinaryRead method which generates an error.
I have to get video url uploaded on kaltura by entryId. I have seen kaltura api, but didn't get proper solution for that.I got something in php code:
$ks = $client->session->start($secret, $userId, KalturaSessionType::ADMIN, $partnerId, 86400, 'disableentitlement');
$client->setKs($ks);
$client->startMultiRequest();
$entryId = '1_u7aj9kasw'; //replace this with your entry Id
$client->flavorAsset->getwebplayablebyentryid($entryId);
$req1ResultFlavorId = '{1:result:0:id}'; //get the first flavor from the result of getwebplayablebyentryid
$client->flavorAsset->geturl($req1ResultFlavorId); //this action will return a valid download URL
$multiRequestResults = $client->doMultiRequest();
$downloadUrl = $multiRequestResults[1];
echo 'The entry download URL is: '.$downloadUrl;
but i have to do it with java ,what i have tried like :
KalturaConfiguration config = new KalturaConfiguration();
config.setEndpoint(envConfiguration.getKalturaUrl());
KalturaClient client = new KalturaClient(config);
String ks = client.generateSession(envConfiguration.getKalturaSecretKey(), "TestUploader",
KalturaSessionType.ADMIN, 101);
client.setKs(ks);
client.startMultiRequest();
String url = client.getFlavorAssetService().getUrl("entryid");
log.debug("url is::::::"+ url);
but i am getting url null .Please help.
Thanks in advance !!!
When Twilio invokes a callback method to fetch the TwiML <Say> for Voice, I see that Twilio sets "x-twilio-signature" in the HTTP header.
I need to verify that the actual request came from Twilio.
I have a simple war file running on Tomcat and the app is built using Spring.
I did something like the following:
//Get the TwilioUtils object initialized
TwilioUtils twilioUtils = new TwilioUtils("******myAuthToken");
//Get the URL from HttpRequest
String url = httpRequest.getRequestURL().toString();
Map<String, String> allRequestParams = getAllRequestParams(httpRequest);
Map<String, String> headers = getAllRequestHeaders(httpRequest);
//Get the signature generated for the Url and request parameters
//allRequestParams is a map of all request values posted to my service by Twilio
String validSig = twilioUtils.getValidationSignature(url, allRequestParams);
//Get the x-twilio-signature value from the http header map
String xTwilioSignature = headers.get("x-twilio-signatureā€¯);
//This is different from what I get below
logger.info("validSig = " + validSig);
logger.info("xTwilioSignature = " + xTwilioSignature );
//This is always false
logger.info("Signature matched : " + twilioUtils.validateRequest(xTwilioSignature, url,
allRequestParams));
I would like to know what am I doing wrong. Is my approach to validate "x-twilio-signature" incorrect?
If it is incorrect, what's the right way to do it?
I am using the helper library class TwilioUtils provided by Twilio to validate it.
All the time the signature from Twilio is different from what I get from the TwilioUtils object.
Megan from Twilio here.
Are you following the steps suggested in the security documentation?
validateRequest expects three arguments. I believe you're missing the url there.
Consider this example:
public class TwilioUtilsExample {
public static void main(String[] args) {
// Account details
String accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
String authToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
//This is the signature we expect
String expected_sig = "SSSSSSSSSSSSSSSSSSSSSSSSSSSS";
//This is the url that twilio requested
String url = "http://UUUUUUUUUUUUUUU";
//These are the post params twilio sent in its request
Map<String,String> params = new HashMap<String,String>();
// Be sure to see the signing notes at twilio.com/docs/security
TwilioUtils util = new TwilioUtils(authToken, accountSid);
boolean result = util.validateRequest(expected_sig, url, params);
if (result) {
System.out.print( "The signature is valid!\n" );
} else {
System.out.print( "The signature was NOT VALID. It might have been spoofed!\n" );
}
}
}
Hope this is helpful!
I'm looking to leverage RackSpace's CloudFiles platform for large object storage (word docs, images, etc). Following some of their guides, I found a useful code snippet, that looks like it should work, but doesn't in my case.
Iterable<Module> modules = ImmutableSet.<Module> of(
new Log4JLoggingModule());
Properties properties = new Properties();
properties.setProperty(LocationConstants.PROPERTY_ZONE, ZONE);
properties.setProperty(LocationConstants.PROPERTY_REGION, "ORD");
CloudFilesClient cloudFilesClient = ContextBuilder.newBuilder(PROVIDER)
.credentials(username, apiKey)
.overrides(properties)
.modules(modules)
.buildApi(CloudFilesClient.class);
The problem is that when this code executes, it tries to log me in the IAD (Virginia) instance of CloudFiles. My organization's goal is to use the ORD (Chicago) instance as primary to be colocated with our cloud and use DFW as a back up environment. The login response results in the IAD instance coming back first, so I'm assuming JClouds is using that. Browsing around, it looks like the ZONE/REGION attributes are ignored for CloudFiles. I was wondering if there is any way to override the code that comes back for authentication to loop through the returned providers and choose which one to login to.
Update:
The accepted answer is mostly good, with some more info available in this snippet:
RestContext<CommonSwiftClient, CommonSwiftAsyncClient> swift = cloudFilesClient.unwrap();
CommonSwiftClient client = swift.getApi();
SwiftObject object = client.newSwiftObject();
object.getInfo().setName(FILENAME + SUFFIX);
object.setPayload("This is my payload."); //input stream.
String id = client.putObject(CONTAINER, object);
System.out.println(id);
SwiftObject obj2 = client.getObject(CONTAINER,FILENAME + SUFFIX);
System.out.println(obj2.getPayload());
We are working on the next version of jclouds (1.7.1) that should include multi-region support for Rackspace Cloud Files and OpenStack Swift. In the meantime you might be able to use this code as a workaround.
private void uploadToRackspaceRegion() {
Iterable<Module> modules = ImmutableSet.<Module> of(new Log4JLoggingModule());
String provider = "swift-keystone"; //Region selection is limited to swift-keystone provider
String identity = "username";
String credential = "password";
String endpoint = "https://identity.api.rackspacecloud.com/v2.0/";
String region = "ORD";
Properties overrides = new Properties();
overrides.setProperty(LocationConstants.PROPERTY_REGION, region);
overrides.setProperty(Constants.PROPERTY_API_VERSION, "2");
BlobStoreContext context = ContextBuilder.newBuilder(provider)
.endpoint(endpoint)
.credentials(identity, credential)
.modules(modules)
.overrides(overrides)
.buildView(BlobStoreContext.class);
RestContext<CommonSwiftClient, CommonSwiftAsyncClient> swift = context.unwrap();
CommonSwiftClient client = swift.getApi();
SwiftObject uploadObject = client.newSwiftObject();
uploadObject.getInfo().setName("test.txt");
uploadObject.setPayload("This is my payload."); //input stream.
String eTag = client.putObject("jclouds", uploadObject);
System.out.println("eTag = " + eTag);
SwiftObject downloadObject = client.getObject("jclouds", "test.txt");
System.out.println("downloadObject = " + downloadObject.getPayload());
context.close();
}
Use swift as you would Cloud Files. Keep in mind that if you need to use Cloud Files CDN stuff, the above won't work for that. Also, know that this way of doing things will eventually be deprecated.
The following is my piece of code
SmbFile catalExp = new SmbFile("smb://<Shared machine name>/Project share/Home/4. Folders/planning - Design & Exec/sample.txt",
new NtlmPasswordAuthentication(LoadProp.getShrdDomain(),"user","paswd"));
In this i am getting the error
jcifs.smb.SmbException: The network name cannot be found
at jcifs.smb.SmbTransport.send(SmbTransport.java:753)
at jcifs.smb.SmbSession.sessionSetup(SmbSession.java:140)
at jcifs.smb.SmbSession.send(SmbSession.java:103)
at jcifs.smb.SmbTree.treeConnect(SmbTree.java:132)
at jcifs.smb.SmbFile.connect(SmbFile.java:674)
at jcifs.smb.SmbFile.connect0(SmbFile.java:644)
at jcifs.smb.SmbFile.open0(SmbFile.java:700)
at jcifs.smb.SmbFile.createNewFile(SmbFile.java:2027)
Is this anything to do with the user rights to that particular shared folder or am I doing anything wrong
Please advice
I ran into this error message, and it turned out the problem was that my network path was incorrect. You'll want to ensure that the NtlmPasswordAuthentication object is configured correctly, that your network path is correct, and that you've set the jcifs.netbios.wins property correctly, as indicated in the first example on this page.
For example, to load a remote properties file:
final NtlmPasswordAuthentication AUTH = new NtlmPasswordAuthentication("domainname", "username", "password");
Config.setProperty("jcifs.netbios.wins", "10.10.1.1");
Properties props = new Properties();
InputStream in = new SmbFileInputStream(new SmbFile("smb://10.10.1.1:445/rootfolder/path/filename.properties", AUTH));
props.load(in);
(You'll need to add try/catch and input stream closing)
A good way to ensure that all of your parameters are correct is to test logging into and locating the file using a smb/cifs client. For example smbclient on linux/unix:
smbclient -Uusername -p 139 //10.10.1.1/rootfolder
The domain is displayed at the top when you login with smbclient:
Domain=[DOMAINNAME]
..and you can navigate to your file to make sure you've got the path correct.
After running into this issue for almost 1 day i realize that these exception is meaningless
I was just giving wrong path of server side location
Below is the peace of groovy code worked for me
String domain = "domain"
String user = "username"
String pass = "password"
String IP = "xx.yy.zz.aa"
String sharedFolder="//my//path//to//server//";
String path="smb://$IP"+sharedFolder+"test.txt";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, user, pass );
SmbFile smbFile = new SmbFile(path,auth);
SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile);
smbfos.write("testing....and writing to a file".getBytes());
System.out.println("completed ...nice !");
Well I'm getting this error also but only on one device, my code that works on Android 4.04 is
String strprog = "STRING CREATED| "; //debug log string
try {
strprog += "NTLM| ";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("username:password");
strprog += "SMB| ";
SmbFile file = new SmbFile("smb://<pcname>/foldername/filename.txt",auth);
strprog += "EXIST| ";
String there = String.valueOf(file.exists());
strprog += "View| ";
TextView pp;
pp = (TextView) findViewById(R.id.tv);
pp.setText(there);
} catch (Exception e) {
// TODO Auto-generated catch block
strprog += "ERROR! ";
TextView ll;
ll = (TextView) findViewById(R.id.tv);
ll.setText(strprog + e.getStackTrace().toString() + " " + e.getMessage() + " " + e.getLocalizedMessage() );
}
The only difference I see is where you have your NtlmPasswordAuth compared to mine.
But as I stated for some reason this throws null input param on Andriod 2.0 when I dive deeper then smb://host but I hope this helps you out.
I had this problem, and it turned out that I did not see what the share name was that was mapped to my Windows shared drive... So, using Mac OS, I ran:
smbutil view smb://MYUSERNAME#HOSTNAME
After I was prompted for my password, I then was displayed a list of share names (that weren't evident when I looked at this stuff using Windows). Once I found my share name, it was as simple as using that when connecting with JCIFS:
new SmbFile("smb://HOSTNAME/SHARENAME/path/I/was/trying/to/access", auth);