This might already be asked but I just searched through for hours. I am trying to comment on a post that I made with my web app while signed in on facebook. I do not want to post a comment as the Web app page admin. Id like to post the comment as a user signed into facebook on my site while the post id is remembered. when I try to post a comment I get this
Publishing comments through the API is only available for page access tokens
I'm using this piece of code
FB.api(response.data[0].id+'/comments', 'post',{message: "good work"},function(response){
console.log(response);
});
I'm starting to think that it is not possible anymore. I just would like someone to give me a concrete answer about it thank you.
The error message tells you that it is not possible to comment "as User" anymore. You can only comment with a Page Token, which means that you can only comment "as Page".
Changelog: https://developers.facebook.com/docs/graph-api/changelog/version2.10#gapi-90-comments
POST and DELETE /{object-id}/comments — This node now requires a valid
page access token.
Basic Full Page Login Example:
//<![CDATA[
/* external.js */
var doc, bod, I, fI, old = onload; // for use on other loads
onload = function(){
if(old)old(); // change old var name if using technique on other pages
doc = document; bod = doc.body;
I = function(id){
return doc.getElementById(id);
}
fI = function(client_id, redirect_uri, onLogin, onLoginContext){
var c = onLoginContext || this;
FB.getLoginStatus(function(r){
if(r.status === 'connected'){
onLogin.call(c);
}
else{
location = 'https://www.facebook.com/dialog/oauth?client_id='+client_id+'&redirect_uri='+redirect_uri;
}
});
}
var out = I('out');
fI('571652776188445', 'https://phpglue.com/fakebook', function(){
FB.api('708713672667337', 'post', {message:'Testing Facebook JavaScript SDK'}, function(r){
out.innerHTML = r.message;
});
}); // app I will never fully develop
}
//]]>
/* external.css */
html,body{
padding:0; margin:0;
}
body{
background:#000; overflow-y:scroll;
}
.main{
width:936px; background:#fff; padding:20px; margin:0 auto;
}
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<meta http-equiv='content-type' content='text/html;charset=utf-8' />
<meta name='viewport' content='width=device-width' />
<title>Facebook Basic Full Page Login</title>
<link type='text/css' rel='stylesheet' href='external.css' />
<script type='text/javascript' src='https://connect.facebook.net/en_US/sdk.js'></script>
<script type='text/javascript' src='external.js'></script>
</head>
<body>
<div class='main'>
<div id='out'>You have to test this from Your Facebook App</div>
</div>
</body>
</html>
Related
Please excuse this extremely trivial question but I just started to experiment a little with Javascript but can't seem to figure out where I went wrong with this.
Uncaught ReferenceError: temperature is not defined
Every little tip is greatly appreciated!
$.ajax({
url: 'https://api.weather.gov/gridpoints/EWX/92,61/forecast/hourly' }).done(function(res) {
var temp = res.properties.periods[0].temperature;
});
function test () {
document.getElementById('temperature').innerHTML = temp;
}
Use an external script tag in your head like <head><script type='text/javascript' src='folder/file.js'></script></head>. On file.js it would be like $(function(){ /* put all your code in here */ });. Of course, if you want to do something after an asynchronous activity, it must happen then. See the following:
//<![CDATA[
/* js/external.js */
$(function(){ // jQuery load
$.get('https://api.weather.gov/gridpoints/EWX/92,61/forecast/hourly', function(resultObj){
$('#out').html(resultObj.properties.periods[0].temperature+'° F');
});
}); // jQuery load end
//]]>
/* css/external.css */
*{
box-sizing:border-box; padding:0; margin:0;
}
html,body{
width:100%; height:100%;
}
body{
background:#ccc;
}
#content{
padding:7px 5px;
}
#out{
margin-top:10px;
}
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<meta charset='UTF-8' /><meta name='viewport' content='width=device-width, height=device-height, initial-scale:1' />
<title>Test Template</title>
<link type='text/css' rel='stylesheet' href='css/external.css' />
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>
<script type='text/javascript' src='js/external.js'></script>
</head>
<body>
<div id='content'>
Look in the <head> above then at the jQuery below
<div id='out'></div>
</div>
</body>
</html>
AJAX is an asynchronous call. temp will always be undefined every time function test is called. You can achieve what you wanted by doing the following:
function test() {
$.ajax({
url: 'https://api.weather.gov/gridpoints/EWX/92,61/forecast/hourly'
})
.done(function(res) {
var temp = res.properties.periods[0].temperature;
document.getElementById('temperature').innerHTML = temp;
});
}
First of all, give thanks for reading my question and try to help me and apologize for my English.
I have the following problem ...
I would like from the html to execute a function of a js file that I have created, to which you pass two parameters: the name of the map and the id where the map should be loaded. But being a module type tells me it is not defined. However, if that file js is not a module type and does not have any import if it recognizes and executes it.
My code is the following ...
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Map Generator</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script type="module" src='./js/index.js'></script>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.46.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.46.0/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; height:100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
customMap.addMap("icgc", "map");
</script>
</body>
</html>
index.js file
import MapFunctions from './class/MapFunctions.js'
// new MapFunctions().createMap("openstreetmaps", "map");
var customMap = {
addMap: function name(base, target) {
new MapFunctions().createMap(base, target);
}
}
With the constructor it works, but the purpose is that from the index.html you only have to make the call to the function customMap.addMap () and only importing the file index.js
Here you have the repository in case you see it there more clearly
Thank you
Hello and thank you in advance, I'm currently looking through the documentation for facebook graph api and I am trying to understand it.
/* make the API call */
FB.api(
"/{photo-id}",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
The graph api has a convention of using the id(as seen above) of the node you want to get data from. I'm not sure where to get the id for each of the nodes. If someone could explain it or point me in the right direction I would really appreciate it. Thank you again.
Here is a Facebook example to get your pictures:
// myapp.js
function fbAsyncInit(){
FB.init({
appId: 'your-app-id',
xfbml: true,
version: 'v2.8'
});
FB.getLoginStatus(function(r){
if(r.status === 'connected'){
// all the magic must happen here
FB.api('me/photos?type=uploaded', function(u){
var d = u.data; // array of photo info
for(var i=0,l=d.length; i<l; i++){
// individual photo data
FB.api(d[i].id, function(p){
// p is photo
});
}
});
}
else{
location = 'https://www.facebook.com/dialog/oauth?client_id=yourClientIdHere&redirect_uri=yourWebPageToRedirectToWhenLoggedIn';
}
});
// remove comments to see errors
//FB.AppEvents.logPageView();
}
/* external.css */
html,body{
margin:0; padding:0;
}
.main{
width:980px; margin:0 auto;
}
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<meta http-equiv='content-type' content='text/html;charset=utf-8' />
<link type='text/css' rel='stylesheet' href='external.css' />
<script type='text/javascript' src='myapp.js'></script>
<script type='text/javascript' src='//connect.facebook.net/en_US/sdk.js'></script>
</head>
<body>
<div class='main'>
Nothing to See But the JavaScript and HTML <script> tag order
</div>
</body>
</html>
How to get full url which starts url with http://sin1.g.adnxs.com
here is my code
<div id="testingurl">
<div class="ads98E6LYS20621080">
<!-- we are getting this script dynamically -->
<iframe src="http://testing.com">
if the anchor link start with http://sin1.g.adnxs.com then alert
</iframe>
<!-- we are getting this script dynamically -->
</div>
</div>
if(window.location.origin == 'http://sin1.g.adnxs.com'){
alert('some alert');
}
Use this logic
$( document ).ready(function() {
if (window.location.href.startsWith('http://sin1.g.adnxs.com')){
alert('Your message') ;
}
});
Are you looking something like this:
if (window.location.href.indexOf("http://www.sin1.g.adnxs.com") > -1) {
alert(window.location.href);
}
As other suggested, you can use window.location.origin in order to get that url
Example:
if(window.location.origin === 'http://sin1.g.adnxs.com'){
alert('alert');
}
Generally you can use window.location for:
window.location.href returns the href (URL) of the current page
window.location.hostname returns the domain name of the web host
window.location.pathname returns the path and filename of current page
window.location.protocol returns the web protocol used (http:// or https://)
window.location.assign loads a new document
More info can be found here:
https://developer.mozilla.org/en-US/docs/Web/API/Window.location
EDIT:
Please have a look at the following example.
In case you have two web pages, parent.html and content.html and content.html is
displayed within parent.html using an iframe.
If you want check the URL of parent.html within content.html you can use the following script:
-------------------------- parent.html
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<style>
</style>
<script>
window.name = 'parent';
</script>
</head>
<body>
PARENT
<iframe src="content.html" width="200" height="200"></iframe>
</body>
</html>
-------------------------- content.html
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<style>
body {
background-color: red;
}
</style>
<script>
app = {
start: function () {
window.name = 'content';
var parent = window.parent;
console.log(parent.name);
if (parent.location.origin === 'http://sin1.g.adnxs.com') {
alert('alert');
}
}
};
</script>
</head>
<body onload="app.start();">
CONTENT
</body>
</html>
with the following html/js code I am able to successfully call my signalR 2.0 hub if html/js and hub resides on the same server.
<!DOCTYPE html>
<html>
<head>
<title>Test SignalR 2.0</title>
<style type="text/css">
.container {
background-color: #99CCFF;
border: thick solid #808080;
padding: 20px;
margin: 20px;
}
</style>
</head>
<body>
<div class="container">
<input type="text" size=100 id="message" />
<input type="button" id="sendmessage" value="Send" />
</div>
<ul id="discussion"></ul>
<!--Script references. -->
<script src="Scripts/jquery-1.6.4.min.js"></script>
<script src="Scripts/jquery.signalR-2.0.3.min.js"></script>
<script src="/signalr/hubs"></script>
<script type="text/javascript">
$(function () {
//Instanciating Hub-Class
var srv = $.connection.pvHub;
// Definition of function called by HUB (Server)
srv.client.receiveData = function (message) {
var encodedMsg = $('<div />').text(message).html();
$('#discussion').append('<ul>' + encodedMsg + '</ul><br>');
};
// Start the connection.
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
// call HUB function (on Server)
srv.server.getBnoData($('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
</script>
Now I am trying to call the hub with the same html/js file located on a client. But no success.
I think, there are some issues with the hub proxy and the URL of my hub on instantiating the connection and start it. But strictly speaking no idea how to resolve this.
Any idea?
thx.
You just need to enable Cross Domain support. Read this:
http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-javascript-client#crossdomain
Also, in case you have already set it up, you have to update your client code to point at the right endpoint, by updating the /signalr/hubs relative address to an absolute one, and by specifying a valid absolute address for $.connection.hub.url. Something like:
<script src="http://foo.com/signalr/hubs"></script>
<script>
...
$.connection.hub.url = 'http://foo.com/signalr';
...
</script>