我所拥有的是“随机报价生成器”。顾名思义,它会在按钮点击时生成随机引号。在我这个所谓的应用程序中,我有一个按钮,应该在Facebook墙上发布'生成的引用'。在我的推特按钮的情况下,同样的事情顺利进行,而在facebook的情况下,我无法做到这一点。
<script>
$(document).ready(function(){
//alert("hi");
$.getJSON("https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=40",function(json){
//alert("hello");
var colour_arr = ["YellowGreen","Turquoise","Tomato","Teal","SteelBlue","SlateBlue","SeaGreen","SandyBrown","Red","Purple","PaleVioletRed","PaleGreen","Orange","MediumVioletRed","MediumTurquoise","Magenta","LimeGreen","LightSalmon","Khaki","Gold","DodgerBlue","DeepPink","DarkOrange","Crimson","Aquamarine"];
var colour_num = 0;
var num = 0;
var html_quote = "";
/*json.forEach(function(val){
html += "<h3 id='quote'>" + val.content + "</h3>";
});*/
var html_author = "";
html_quote = "<h3 id='quote' class='colour'><i class='fa fa-quote-left' aria-hidden='true'></i>" + json[num].content + "</h3>";
html_author = "<h5 id='author' class='colour'> - " + json[num].title + "</h5>";
$("#quote-column").html(html_quote);
$("#author-column").html(html_author);
$(".colour").css("color",colour_arr[colour_num]);
$(".bg-colour").css("background-color",colour_arr[colour_num]);
$("#new-quote-btn").on("click",function(){
//alert("hello");
colour_num++;
num++;
//alert(num);
html_quote = "<h3 id='quote' class='colour'><i class='fa fa-quote-left' aria-hidden='true'></i>" + json[num].content + "</h3>";
html_author = "<h5 id='author' class='colour'> - " + json[num].title + "</h5>";
$("#quote-column").html(html_quote);
$("#author-column").html(html_author);
$(".my-btn").css("color","white");
$(".colour").css("color",colour_arr[colour_num]);
$(".bg-colour").css("background-color",colour_arr[colour_num]);
});
var randomQuote = json[num].content.replace("<p>","");
randomQuote = randomQuote.replace("</p>","");
$("#twitter-btn").on("click",function(){
//alert(json[num].content);
//var randomQuote = json[num].content.replace("<p>","");
//randomQuote = randomQuote.replace("</p>","");
//alert(randomQuote);
window.open("https://twitter.com/intent/tweet?text=" + randomQuote,"_blank");
//location.href = "https://twitter.com/intent/tweet?text=" + json[num].content;
//$(this).attr("href","https://twitter.com/intent/tweet?text=" + json[num].content);
});
$("#fb-btn").on("click",function(){
window.open("https://www.facebook.com/sharer/sharer.php?u=https://codepen.io/iamrkcheers/pen/gRjoeZ","_blank");
});
});
});
</script>
.box {
background-color : white;
border-radius : 5px;
}
.my-btn {
color : white;
}
#twitter-btn, #fb-btn {
width : 40px;
}
<html>
<body class="bg-colour">
<div class="container-fluid">
<div class="row" id="main-row">
<div class="col-md-12 col-sm-12 col-xs-12" id="main-column">
<br>
<br>
<br>
<br>
<br>
<br>
<div class="row" id="row-containing-block">
<div class="col-md-offset-4 col-md-4 col-sm-offset-3 col-sm-6 col-xs-offset-1 col-xs-10 box" id="column-containing-block">
<br>
<div class="row" id="quote-row">
<div class="col-md-offset-1 col-md-10 col-sm-offset-1 col-sm-10 col-xs-offset-1 col-xs-10" id="quote-column">
<!-- <h3 id="quote"></h3> -->
</div>
</div>
<div class="row" id="author-row">
<div class="col-md-offset-7 col-md-4 col-sm-offset-5 col-sm-6 col-xs-offset-3 col-xs-8" id="author-column">
<!-- <h5 id="author"></h5> -->
</div>
</div>
<br>
<div class="row" id="btn-row">
<div class="col-md-offset-1 col-md-10 col-sm-offset-1 col-sm-10 col-xs-offset-1 col-xs-10" id="btn-column">
<button type="button" class="btn btn-default my-btn bg-colour" id="twitter-btn"><i class="fa fa-twitter" aria-hidden="true"></i></button>
<button type="button" class="btn btn-default my-btn bg-colour" id="fb-btn"><i class="fa fa-facebook" aria-hidden="true"></i></button>
<button type="button" class="btn btn-default my-btn bg-colour pull-right" id="new-quote-btn">New Quote</button>
</div>
</div>
<br>
</div>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
</div>
</div>
</body>
</html>
以下是我的工作实例..
https://codepen.io/iamrkcheers/pen/gRjoeZ
而不是“对此说些什么......”文字,我想要我的'随机引用'。 无论如何要做到这一点?!? Anyhelp表示赞赏。 谢谢。
答案 0 :(得分:0)
尝试这种方法..
using Facebook;
private string PostFacebookWall(string accessToken, string message) {
var responsePost = "";
try {
//create the facebook account object
var objFacebookClient = new FacebookClient(accessToken);
var parameters = new Dictionary<string, object>();
parameters["message"] = message;
responsePost = objFacebookClient.Post("feed", parameters);
}
catch (Exception ex) {
responsePost = "Facebook Posting Error Message: " + ex.Message;
}
return responsePost;
}