Twitter4J - 401:Authentication credentials were missing or incorrect [closed] - twitter4j

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm playing around with the Twitter4J API and am getting the 401:Authentication credentials were missing or incorrect when using the createFriendship method.
I obtain an instance of Twitter as follows:
protected Twitter getApi(String consumerKey, String consumerSecret, String accessToken, String secret) {
AccessToken token = new AccessToken(accessToken, secret);
return new TwitterFactory().getOAuthAuthorizedInstance(consumerKey, consumerSecret, token);
}
Once obtained I can successfully use the updateStatus method to tweet something. However when I try to execute the createFriendship method I get the following error even though the status updates are working fine
Request processing failed; nested
exception is 401:Authentication
credentials were missing or incorrect.
{"request":"\/1\/friendships\/create.json?screen_name=[user]","error":"Incorrect
signature"}
TwitterException{exceptionCode=[564a75a9-01c7e75c],
statusCode=401, retryAfter=0,
rateLimitStatus=null, version=2.1.5}
In the above error the screen_name=[user] the [user] section is replaced with the correct Twitter screen name.
Is there something I am missing?
Thank you

Sorry it was a simple problem with 2 different versions of Twitter4J on the classpath!

Related

How to handle parse JSON errors in Swift [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm new in Swift and though I've read responses to many questions with a similar title, since there are apparently so many ways to handle HTTP calls in Swift, I'm completely confused.
I use URLSession.shared.dataTask to make HTTP calls to an open API and handle the response as
let fiatRates = try! JSONDecoder().decode(FiatResponse.self, from: data!)
DispatchQueue.main.async {
completion(fiatRates)
}
where FiatResponse is
struct FiatResponse: Decodable {
var rates: [String: Float]
var base: String
var date: String
}
When I wrap this is do-catch, I get this warning:
Catch block is unreachable because no errors are thrown in do block
Yet the app crashes with an error in the do block in case the API returns errors or times out. In. such situation the app never runs the catch block.
How can I tweak my code to correctly parse the JSON response and run the catch block, should an error occur?
When you add ! to try the error will not be thrown, instead it will crash the app. To make the do-catch work you need to get rid of the !:
do {
let fiatRates = try JSONDecoder().decode(FiatResponse.self, from: data!)
} catch {
print(error)
}
You can read more about it here, in this blogpost. Also, here is the full documentation.

Stack Exchange API - getting answers for the questions object

I use https://api.stackexchange.com/docs. To get a sample question, I use the address https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow. Thanks to this, he gains a question. The following page shows https://api.stackexchange.com/docs/types/question that with the default filter the question will not have a body. I know I use a filter to get a body filter=withbody that is, the address comes out
https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow&filter=withbody
Now I would like to get answers for the question. That's why I want to use a filter filter=withanswers. This address
https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow&filter=withanswers
returns an error
{
"error_id": 400,
"error_message": "Invalid filter specified",
"error_name": "bad_parameter"
}
How do get answers or comments using a filter?
I think that 2 patterns can be thought for your solution. One is a method using custom filter. Another is a method using the endpoint for retrieving answers.
Pattern 1 :
You can create a custom filter for retrieving answers and answer's body using the endpoint of https://api.stackexchange.com/2.2/questions/### questionId ###.
You can create the custom filters at http://api.stackexchange.com/docs/create-filter.
In your case, you can use this.
question.answers;answer.body;question.body was used as including filters.
The delimiter is ;.
As a result, you retrieve "filter": "!T*hPNRA69ofM1izkPP".
When you use the filter, please do URL encode it.
!T*hPNRA69ofM1izkPP becomes %21T%2ahPNRA69ofM1izkPP.
You can retrieve answers and answer's body using the endpoint.
When the question ID of your question is used, it's https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow&filter=%21T%2ahPNRA69ofM1izkPP.
Result of pattern 1
When you can access to https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow&filter=%21T%2ahPNRA69ofM1izkPP, you can get answers and answer's body.
Pattern 2 :
As the endpoint for retrieving answers, you can use /questions/{ids}/answers. If the question ID is 6827752 in your question, the endpoint is as follows. In this case, in order to retrieve answer's body, filter=withbody is used.
Result of pattern 2
When you can access to https://api.stackexchange.com/2.2/questions/6827752/answers?order=desc&sort=activity&site=stackoverflow&filter=withbody, you can get answer's body.
If this was not useful for you, I'm sorry.

Laravel more time using token [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I would like to know how can I remove token in form POST method because when I need between 10 and 15 min to fill a form and when I send it, I receive a token exception and I lost all my data.
Thank's for help
I wouldn't recommend removing the token. Instead increase the expiry time or after post redirect back with input values.
public function render($request, Exception $e)
{
if ($e instanceof \Illuminate\Session\TokenMismatchException) {
return redirect()->back()->withInput()->with('token', csrf_token());
}
return parent::render($request, $e);
}

Facebook api('/me') not returning username [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to implement a login with Facebook - thus far all is working, apart from the $user data I am being returned does not include the username (which I know does exist).
The array I am being returned is the following (with details purged):
Array ( [id] => ################ [email] => #.##############.co.uk [first_name] => ######## [gender] => male [last_name] => ######## [link] => https://www.facebook.com/app_scoped_user_id/################/ [locale] => en_GB [name] => ######## ######## [timezone] => 1 [updated_time] => 2014-05-06T21:23:33+0000 [verified] => 1 )
Has anyone had experience of this before?
The username field was removed in version 2.0 of the graph API. I'm not aware of any workaround (short of using version 1.0).
This change is listed in the "Removed Endpoints" section of the upgrade guide. You can also see that the "User" reference contains no mention of a username field for version 2.0, but does for version 1.0.
Not all fields are available through the API. You can see exactly what fields are available using the references I've provided above.
Looks like a Facebook Graph API bug.

RESTful web service API documentation with Sphinx [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
What's the best way to markup methods/URLs for a RESTful webservice using ReST/Sphinx? Is there a default domain that's suitable for marking up URLs with their possible parameters, HTTP methods, headers and body content?
Something along the lines of:
.. rest:method:: GET /api/foo
:param bar: A valid bar
:extension: json or xml
Retrieve foos for the given parameters. E.g.::
GET /api/foo.json?bar=baz
Does something like this already exist or is one of the default extensions usable, or will I have to write one myself?
The Sphinx Contrib project also seems to have an HTTP Domain package for documenting RESTful HTTP APIs. You can find its documentation on the Python packages site. I can't speak to its fitness: I'm only just starting to look into Sphinx, and I have a need to document RESTful APIs as well, and noticed this contributed package.
Since there doesn't appear to be any existing solution, I have implemented a very simple HTTP domain that I can use to mark up API methods:
import re
from docutils import nodes
from sphinx import addnodes
from sphinx.locale import l_, _
from sphinx.domains import Domain, ObjType
from sphinx.directives import ObjectDescription
http_method_sig_re = re.compile(r'^(GET|POST|PUT|DELETE)?\s?(\S+)(.*)$')
class HTTPMethod(ObjectDescription):
def handle_signature(self, sig, signode):
m = http_method_sig_re.match(sig)
if m is None:
raise ValueError
verb, url, query = m.groups()
if verb is None:
verb = 'GET'
signode += addnodes.desc_addname(verb, verb)
signode += addnodes.desc_name(url, url)
if query:
params = query.strip().split()
for param in params:
signode += addnodes.desc_optional(param, param)
return url
class HTTPDomain(Domain):
"""HTTP language domain."""
name = 'http'
label = 'HTTP'
object_types = {
'method': ObjType(l_('method'), 'method')
}
directives = {
'method': HTTPMethod
}
def setup(app):
app.add_domain(HTTPDomain)
It allows me to mark up methods like this and they'll be styled somewhat visually nicely:
.. http:method:: GET /api/foo/bar/:id/:slug
:param id: An id
:param slug: A slug
Retrieve list of foobars matching given id.
This was my first foray into both Sphinx and Python, so this should be considered very rudimentary code. If anybody is interested in fleshing this out, please fork this project on Github!