Tumblr API - can GET but not POST - javascript

I'm trying to create a page where users can log in with their tumblr account and fill out a form to post to their blog.
I'm using hello.js with the tumblr module.
I've modified the tumblr module demo and everything seems to be working in terms of logging in and authenticating. However, I'm unable to convince the API to let me use any OAUTH-restricted POST commands. GET commands, such as retrieving a user's followed blogs, work fine. But if I try something simple such as user/follow to follow a new blog, I get a "401 Not Authorized" response.
What could be causing OAUTH restricted GET commands to be working fine, but POST does not?
You can see my testing code live at http://www.jereddanielson.com/testing/tumblr/hello.js-master/demos/tumblr.html
Below is the pertinent javascript. I'm using the OAUTH proxy at https://auth-server.herokuapp.com/
function login(network){
hello( network ).login({scope: 'publish_actions, publish, post, post_actions, follow, follow_actions'}).then( function(r){
// Get followed blogs
hello(network).api({path: '/user/following', method: "get"}).then(function(p){
console.log(p);
console.log("Tried to retrieve followed blogs. Response status: " + p.meta.status + " " + p.meta.msg);
});
// Try to follow a blog
hello(network).api({path: '/user/follow', method: "post", data: {url: "daily-fractal.tumblr.com"}}).then(function(p){
console.log(p);
console.log("Tried to follow a blog. Response status: " + p.meta.status + " " + p.meta.msg);
});
}, function(e){
console.error(e);
});
}
hello.init({
'tumblr' : "bQpjOrKgIu9pWVann1HVOAoW6gOGNoSpcMXIpwjNqghUmkwvgt"
},
{
redirect_uri:'../redirect.html',
oauth_proxy: "https://auth-server.herokuapp.com/proxy"
});
Thanks.

Related

Facebook API returns permission error despite access token being valid

I'm using facebook's API to post on a facebook page, and this the error that comes up.
{
error: {
message: '(#200) If posting to a group, requires app being installed in the group, and \\\n' +
' either publish_to_groups permission with user token, or both pages_read_engagement \\\n' +
' and pages_manage_posts permission with page token; If posting to a page, \\\n' +
' requires both pages_read_engagement and pages_manage_posts as an admin with \\\n' +
' sufficient administrative permission',
type: 'OAuthException',
code: 200,
fbtrace_id: 'AcWINdvgXkS1Apmj4h4LEDZ'
}
}
The message there is incorrect, as I used the token debugger to find out the following.
All required permissions seem to be there, and it is indeed a page type token.
The code is very simple.
I have a feeling this is another case of facebook's terrible error messaging. Any ideas?
Oh god! After hours of debugging - the issue was that I was using a hashtag in the message, which obviously cut off the URL, making the access_token invisible.
Solution - encodeURIComponent(random_tag)
Silly mistake!

geo_ip.js is not working

I am using "http://j.maxmind.com/app/geoip.js" for multilingual site support but this link is throwing 404 error.
Here is the error
Failed to load resource: the server responded with a status of 404 (Not Found)
www.globalenglish.com/:913 Uncaught ReferenceError: geoip_country_code is not defined
chrome-extension://gllmlkidgbagkcikijiljllpdloelocn/contentscript.js:1849 www.globalenglish.com
getuid:1 GET https://api.bizographics.com/v2/getuid?api_key=422935bcbfc445d59f10758c288c…I%252bJLufjW0EE6tV4BHMF43u8yA9qpnPTK8G7tGxJuiy5ReJz%252fscH55wHNbnsJU%253d 403 (Forbidden)
I checked the site here for new link, this link throws 401 error.
I also checked new API here but this also did not work for me. JS Link works but geoip_country_code() is undefined
How to make it work again !!!! Here is fiddle
Thanks
Unfortunately, Maxmind doesn't provide a geoip api through
http://j.maxmind.com/app/geoip.js
anymore. Although it provides another api as
http://js.maxmind.com/js/apis/geoip2/v2.1/geoip2.js
However it requires a domain registration etc. according to Maxmind's website. The link below is a clone of the old api and valid for around one year now.
http://geoapi123.appspot.com/
I've just used this for one of my projects in development stage for a very quick solution. But I strongly suggest you to update your code according to a trustworthy service again.
A working jsfiddle to show how things could play on here; which shows this chunk of code:
$.ajax( {
type: 'GET',
url: '//geoapi123.appspot.com/',
dataType: 'script',
cache: true,
success: function() {
var geo = geoip_country_code() + '|' + geoip_region_name() + '|' + geoip_city() + '|' + geoip_latitude() + '|' + geoip_longitude();
$('#results').html(geo);
}
});
UPDATE:
I realised this answer is still getting attraction. Please be aware it has been years since I wrote this one. The URL I shared does not seem to be working anymore. Also there are much better approaches to handle the problem now.
Actually, there is a message in the console you might have missed :
Users of the GeoIP2 JavaScript API must register their domains at
https://www.maxmind.com/en/javascript_domains
The loading of the library failed because a request is issued to the js.maxmind.com domain with your current hostname (fiddle.jshell.net in your case) as the referrer to ensure that the client was actually making a request from an authorized hostname.
hey guys i'm using This script but i don't know why HTTPS doesn't work when i try to redirect .. it only work With HTTPS
$.ajax({
url: "http://api.petabyet.com/geoip",
success: function(data) {
switch (data.country_code) {
case 'DE':
window.location.href = "https://google.com/de";
break;
}
}
})
</script>

Oauth.io service and social network linking, unlinking?

I'm using https://oauth.io/ service and I'm a little bit unlucky with finding correct documentation on few things:
Is it possible to unauthorize one or another social network from application? In other words destroy permissions for application to use user's settings of that network.
How do I make google plus oauth work:
There is an example for facebook:
OAuth.popup('facebook', function(err, res) {
if (err) {
// do something with error
}
res.get('/me')
.done(function(data) {
alert('Hello ' + data.name)
})
})
It does work for me but I can't figure out how can I make it work with google+ API. When I change provider to google_plus I manage to get authorization token but I'm not sure how to proceed further because calling res.get('/me') doesn't work ('I suppose /me is only for facebook API'). I've tried lots of different other urls that are for google+ but it seems that because G+ doesn't support CORS request it makes request to local oauthd server like so: options.url = config.oauthd_url + '/request/' + options.oauthio.provider + options.url; network returns that no such endpoint exists.
Please if anyone know how to solve this help me.
Thank you
I just ran into this problem too, and I found a jsfiddle
res.get('/plus/v1/people/me').done(function (me) {
$('#connect').slideUp('fast')
$('#res').html(template({
data: me
})).slideDown('fast')
res.get('/plus/v1/people/me/activities/public').done(function(activities) {
$('#activities').html(activitiesTemplate({
data: activities
}))
});
})

How to use Azure mobile service REST api?

The new custom API script allows a lot of customization through any type of connection.
I found that this website Custom API in Azure Mobile Services – Client SDKs describes the custom API.
var client = new WindowsAzure.MobileServiceClient('http://myservice.azure-mobile.net/', 'mykey');
client.invokeApi('query', {
method: 'POST'
});
But I couldn't run this code. It is supposed to show a message "Hello post World!".
I put the code inside tags in an HTML file and ran it but nothing happened.
Any help?
The call you have is making a call to your service, but it's ignoring its response. Assuming you have a custom API called 'query' (since it's what you're passing to invokeApi) with the following body:
exports.post = function(request, response) {
response.send(200, { message: 'Hello world' });
};
Your client code is calling it and (if everything goes fine) receiving the response, but it's not doing anything with it. There are a couple of ways to find out whether the call is being made. For example, you can add a log entry in the API and check the logs in your service:
exports.post = function(request, response) {
console.log('The API was called');
response.send(200, { message: 'Hello world' });
};
Or you can use a networking tool (the browser developer tools or Fiddler, for example) to see if the request is being made. Or you can actually do something with the result in the client side:
var client = new WindowsAzure.MobileServiceClient('http://myservice.azure-mobile.net/', 'mykey');
client.invokeApi('query', {
method: 'POST'
}).done(
function(result) { alert('Result: ' + JSON.stringify(result)); },
function(error) { alert('Error: ' + error); }
);
One thing which you need to look at if you're calling the API from a browser is whether the domain from where the page is being loaded is in the 'allow requests from host names' list, under the 'configure' tab, 'cross-origin resource sharing (cors)' section. If it's not, then you may get an error instead of the response you want.

FB Graph API: Posting as a page, to a different page

I'm using Facebook's Javascript SDK, and I need a way to let users post to a specific page impersonating one of the pages they own. Posting as the user works perfectly, but I can seem to get this right:
var data = {
access_token: access,
message: "Hello"
};
FB.api("/" + page_id + "/feed", "post", data, function(response) {
console.log(response);
});
page_id is the numeric ID of the specific page I want to post to, and access is the access_token retrieved from the "me/accounts" api, using the manage_pages authorization.
The output I recieve from the response variable is the following object:
error: Object
code: 200
message: "(#200) Posts where the actor is a page cannot also include a target_id"
type: "OAuthException"
I couldn't find the answer to this anywhere. Is this just not possible? It can't be.
quick googling suggests it's not possible:
https://stackoverflow.com/questions/9706873/post-on-wall-fan-page-to-a-fan-page-that-likes
How to Post with Application Name
also, take a look at the old REST API documentation: https://developers.facebook.com/docs/reference/rest/stream.publish/
target_id
Note: If you specify a Page ID as the uid, you cannot specify a
target_id. Pages cannot write on other users' Walls.
Note: You cannot publish to an application profile page's Wall.

Categories