Twitter4j with a twitter4j.properties file - twitter4j

I'm trying to post to Twitter using Twitter4j and putting my OAuth credentials in a twitter4j.properties file as per the documentation on http://twitter4j.org.
However I'm stuck as to properly post to Twitter using the credentials this file, as I can only find examples that use ConfigurationBuilder and there's no clear example on which methods to use when the credentials are all stored in a twitter4j.properties file.
I've tried both:
Twitter twitter = TwitterFactory.getSingleton();
twitter.updateStatus("My status");
and
Twitter twitter = new TwitterFactory().getInstance();
twitter.updateStatus("My status");
both of which give me an "Authentication credentials are missing" error.
I've looked at the examples that come with Twitter4j and they involve getting the Access Tokens through a URL callback, which I really don't need as I already have obtained all the credentials from https://apps.twitter.com/
I realise that I could just use the new ConfigurationBuilder() method but this forces me to copy and paste the keys into each of my classes which is time consuming and looks clunky. What's the proper way to set credentials from the twitter4j.properties file?

You can just place it in src/main/resources/twitter4j.properties and then use it:
//scala
val tweet4u = TwitterFactory.getSingleton()
tweet4u.updateStatus("Tes1t")

After some searching, I understand now that the twitter4j.properties file had to be placed in the WEB-INF folder in my case, as I am running a Google App Engine servlet.
The wording on http://twitter4j.org/en/configuration.html is vague and ambiguous, as it simply states that the file twitter4j.properties should be placed in "either the current directory or root of the classpath directory". In my case I was originally placing it in the same directory as my other source files, which meant that Twitter4J couldn't find it ostensibly because it only searched in the root of the classpath directory, which I am going to assume in my case it's WEB-INF.

Related

Angular developers need a path to call for the content from aem page

I generated the json file and gave the path /bin//filename.json . I am able to see the json file in author mode but not in publish. Our aem ops team says they cannot make bin as public. Tried to change the path, using js generated the json path file now at path /content//***/filename.json which I am able to see in author mode but not in publish.
My question is is there any other way that I can try . Please if any other ideas do comment.
Thank you.
Or just simple: Angular get content of page by call .infinity.json
Examp:
Your page is: /mysite/en/home.html
We change to : /mysite/en/home.infinity.json
For more detail: https://forums.adobe.com/thread/2337725
Good luck
We open using url under /bin/.. for SlingServlet
First create a slingSevlet
#SlingServlet(paths="/bin/filename.json", methods = "GET", metatype=true)
Then check the filter and make sure that /bin/filename.json accepts GET requests:
curl 'http://localhost:4502/system/console/configMgr'
Search for 'Apache Sling Referrer Filter'
Check the configuration

Downloading and Moving OneDrive files from shared link directory

I am looking for assistance to find out how I can download and move a OneDrive file that is accessed through a shared directory, via the shared link method of sharing.
I have two users:
user 'A' who is a Microsoft Consumer and has a regular OneDrive account and will host a csv file 'test.csv' in a folder 'toshare'
and user 'B' who is also a regular Microsoft Consumer who should use the graph API to download test.csv and then move the file to a subdirectory /toshare/archive
Aside: I am currently using the chrome app "advanced REST client" to manually make the REST calls, and am getting Authenticated OAuth BEARER tokens by inspecting network traffic from Microsoft's online "Graph Explorer" tool. After we understand the calls, we'll integrate it into our Java app.
I have succesfully followed the instructions here:
https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/shares_get
to view the folder contents.
To be more explicit, user 'A' has went into OneDrive and has right clicked the folder 'toshare' and selected shareLink. I have converted the shareLink to a share token and then used the following API call with the Graph API as user 'B':
GET https://graph.microsoft.com/v1.0/shares/<share-token>/root?$expand=children
this shows me all the files in the directory, which includes 'test.csv'
Now, using this information, how can I download test.csv? Assuming user 'B' doesn't know the name of the file, but can identify it by being a .csv file (we can do this in code). There does not appear to be much documentation on how to download the files through a share.
The closest I've gotten was to take the "webUrl" attribute of the children object for my file, and then turn that into a share token and call
GET https://graph.microsoft.com/v1.0/shares/<child-share-token>/root
This will show me the file meta-data. and then I try to download it by roughly following the api documentation to download https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/item_downloadcontent
GET https://graph.microsoft.com/v1.0/shares/<child-share-token>/root/content
This is interesting because this works if I make the call with user 'A' but does not work for user 'B' who instead gets a 403 in advanced REST client. (If I run it in Graph Explorer, I get "The site in the encoded share URI is invalid." instead, which I've discovered with other experimentation, really means there's an authorization issue.)
GET https://graph.microsoft.com/v1.0/shares/<share-token>/root:/test.csv:/content
Also does not work, it returns: "400 Bad Request" with message: "Resource not found for the segment 'root:'." It seems like the path style file navigation does not work for shared directories?
At this point I'm rather stuck. After downloading the file, I also would like to move it into a subdirectory, denoting that it has already been read in. I'd also like to get this working for OneDrive for Business, but that seems to be another set of challenges that I'll leave for another day.
Any insight would be great thanks,
Jeremy
It's best to consider the shares/{id} segments to be similar to drives/{id}, at which point all of the previous documentation around children access is applicable. Given your scenario I'd use the path syntax:
https://graph.microsoft.com/v1.0/shares/<share-token>/root/children/test.csv
This obviously necessitates knowing the file name, but it sounds like you already have an algorithm to do that.
Theoretically your approach for creating a child-share-token would work, but it would now require that User B both provide authentication as well as to have explicit permissions. Since your share-token was a sharing link User B is most likely getting permission by virtue of the fact that they have the URL, in which case generating a new one is probably removing the special token that allows this to work. That's why it's best to always use the original share-token where possible.
Similar rules will apply to move the file. First off, we'll assume that the sharing link provides the ability to "Edit" otherwise none of this will work :). Second, we'll assume that the archive folder already exists (if it doesn't you'd need to create it using a POST to https://graph.microsoft.com/v1.0/shares/<share-token>/root/children that looks like what we've documented here).
To move the file you'd want to PATCH to https://graph.microsoft.com/v1.0/shares/<share-token>/root/children/test.csv and provide a new parentReference as documented here. It's always best to use id values if you have them, but you should also be able to provide the path to the parent in the form of /shares/<share-token>/root/children/archive.

File Upload: File Upload URL not provided

I've been trying to get file uploads to work, following the instructions for both Dropbox and S3 but each time I just get this message:
File Upload URL not provided
It doesn't seem to be making any calls to the server. I've found this mention of a bug around file uploads:
https://github.com/formio/ngFormio/issues/322
But I suspect that applies if you're hosting it yourself. I'm using the cloud version.
I've configured it with e.g. the S3 bucket's URL, authentication etc.
What does this error actually mean?
Update: here's the syntax I'm using:
<formio form="https://formview.io/#/xxxxxxxxxxxxxxxxxxx/applicationform" url="'https://formview.io/#/xxxxxxxxxxxxxxxxxxx/applicationform'"></formio>
Thanks
In order to make the uploads work, you need to provide the URL of your form, which is used to generate the upload token to upload the files to the 3rd party providers. This can be done in one of two ways.
<formio src="'https://examples.form.io/example'"></formio>
You would use above if you wish to render the form from the JSON REST API of the form. In many cases, you may wish to provide the actual form object (which I suspect is what you are doing) like so.
<formio form="{...}"></formio>
This works fine for rendering the form, but it does not provide the URL context for file uploads. For this reason, we have the url parameter which you can include along with your form object for file uploads to work.
<formio form="{...}" url="'https://examples.form.io/example'"></formio>
Providing the url this way is passive. The form will not try to submit to that url, but rather just use it as the url configuration for file uploads.

C# Dropbox Api retrieve files of public shared folder

i would like to ask, if there's any way to retrieve files links of folder which is publicly shared. Like someone create random public folder(everyone can view it) and put some random files into it. So i need to get all files links from that folder. All i know is link to that folder in format: https://www.dropbox.com/sh/[code]/[code].
Can i do that by using dropbox api, or the only option is to scrape dropbox page directly?
Here is a copy paste example:
using Dropbox.Api;
using Dropbox.Api.Files;
...
// AccessToken - get it from app console
// FolderToDownload - https://www.dropbox.com/sh/{unicorn_string}?dl=0
using (var dbx = new DropboxClient(_dropboxSettings.AccessToken))
{
var sharedLink = new SharedLink(_dropboxSettings.FolderToDownload);
var sharedFiles = await dbx.Files.ListFolderAsync(path: "", sharedLink: sharedLink);
foreach (var file in sharedFiles.Entries)
{
}
}
The documentation wasn't clear about setting path to an empty string when using it with publicly shared folders.
The official way to get information about a particular shared link is to use the Dropbox API's /2/sharing/get_shared_link_metadata endpoint:
https://www.dropbox.com/developers/documentation/http/documentation#sharing-get_shared_link_metadata
In the official Dropbox .NET SDK that's the GetSharedLinkMetadataAsync method:
https://dropbox.github.io/dropbox-sdk-dotnet/html/M_Dropbox_Api_Sharing_Routes_SharingUserRoutes_GetSharedLinkMetadataAsync_1.htm
This unfortunately doesn't offer the list of files though. We'll consider that a feature request.
Note that scraping the site would be error prone and likely to break without warning. (It's also against the terms anyway.)
Edit:
Dropbox API v2 now supports listing the contents of a shared link for a folder. This can be accomplished using the same interface as listing a folder in a connected user's account, via the list_folder functionality. To list the contents of a shared link for a folder, you instead provide the shared link URL in the shared_link parameter to /2/files/list_folder:
https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder
If you're using an official SDK, there will also be a corresponding method for this endpoint. In the .NET SDK that's available as ListFolderAsync:
https://dropbox.github.io/dropbox-sdk-dotnet/html/M_Dropbox_Api_Files_Routes_FilesUserRoutes_ListFolderAsync_1.htm

Bucket URL access denied

I created my first bucket, and when trying to access it by typing storage.googleapis.com/mybucket, I get the following in my browser. I am totally ignorant in respect to all things code, and only would like to be able to solve this issue in order to be able to use a WordPress plugin, WP2Cloud, which integrates Google Cloud Storage with WordPress. Here's what's in my browser:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>AccessDenied</Code>
<Message>Access denied.</Message>
</Error
Any help will be appreciated!
You can not use storage.googleapis.com/mybucket or mybucket.storage.googleapis.com directly from browser. You need to pass GoogleAccessId,Expires, Signature.
If you want to use from browser you need to use Signed URLs
https://developers.google.com/storage/docs/accesscontrol#Signed-URLs
example of Signed-URLs:
http://mybucket.storage.googleapis.com/testdata.txt?GoogleAccessId=1234567890123#developer.gserviceaccount.com&Expires=1331155464&Signature=BClz9e4UA2MRRDX62TPd8sNpUCxVsqUDG3YGPWvPcwN%2BmWBPqwgUYcOSszCPlgWREeF7oPGowkeKk7J4WApzkzxERdOQmAdrvshKSzUHg8Jqp1lw9tbiJfE2ExdOOIoJVmGLoDeAGnfzCd4fTsWcLbal9sFpqXsQI8IQi1493mw%3D